Navigation


Custom 404 Search Page with PHP and Apache

2008-06-05 @ 02:59pm, PHP, Nate Tallman, Comments (0)

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 smile

Nate

Name:

Email:

Location:

URL:

Smileys

Remember my personal information

Notify me of follow-up comments?

Twitter Feed

@ztpkng True about that. Also, people keep saying the rendering engine is faster. I'm still not seeing it, but I think Chrome has potential.
09-05 8:29


Category


Archive


Links

Syndication