Custom 404 Search Page with PHP and Apache
Apache Config:
ErrorDocument 404 /path/to/some/script.php
In your php search script:
Read $_SERVER[’REDIRECT_URL’] or $_SERVER[’REQUEST_URI’] to get the original request that triggered the 404 and perform your search on that.
This will return a 404 to the user-agent, but for FF, IE, and Safari, they will display the custom 404 page as long as the content-length is greater that 512 bytes.
Some people will tell you to do some crazy mod_rewriting and 302 redirect to a script that does your search.
The with that method is that you aren’t returning a 404 to the user-agent. The benefit is trounced by the added overhead of the server returning a result forcing the browser to make a second request. The end result is essentially the same. While a user-agent is not forced to display the custom content from a 404, most do.
Of course, if you’re using a decent framework, there’s no such thing as 404’s and you handle exceptions anyways, right?
Comment if you must
Nate
Next entry: USPS (United States Parcel Stealers)
Previous entry: Cognizant Reckoning