Martin's suggestion is the standard way of doing it. Make a tile server that does this simple function and you'll notice your server runs faster. Processing a 404 is time consuming.
If you'd like to see a Perl example, see http://www.usnaviguide.com/ws-2008-02 - look for download.zip -John Coryat -- You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group. To view this discussion on the web visit https://groups.google.com/d/msg/google-maps-js-api-v3/-/jOZinpl6fqoJ. To post to this group, send email to google-maps-js-api-v3@googlegroups.com. To unsubscribe from this group, send email to google-maps-js-api-v3+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.