bleggee
asked on
Best way to handle web page Redirects and web page "Missing 404" error capture (Apache)
Hi all - I am wondering what the best way is to:
#1 Send someone to a certain error-handling web page within a site instead of generating a 404 error in the event of a URL not found. Something like a "missing" spec or a custom error page?
#2 Send someone to http://example.com/hello.php if they left off the extension and just typed http://example.com/hello
- Brian
#1 Send someone to a certain error-handling web page within a site instead of generating a 404 error in the event of a URL not found. Something like a "missing" spec or a custom error page?
#2 Send someone to http://example.com/hello.php if they left off the extension and just typed http://example.com/hello
- Brian
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If using Apache you can use one of two options:
Using mod_alias:
Just my two cents and soapbox here: Keep in mind if the folder /hello does not exist that is an http status code of "404 file not found" status. So, if you're intention is to do this for everything that doesn't exist then you might want to just redirect the 404 errors to your hello page otherwise scalability of making a bunch of rewrites to anticipate human behavior becomes a full-time job. Again, that's my two cents there.
Using mod_alias:
RedirectMatch 301 ^/hello/ http://example.com/hello.php
Using mod_rewrite:RewriteCond %{REQUEST_URI} !^/hello\.php$ [NC]
RewriteRule ^hello.* http://example.com/hello.php [R=301,NC,L]
mod_alias uses Redirect and RedirectMatch directives whereas mod_rewrite uses Rewrite directives. Both options will do the 301 permanent redirect for you unless you want to switch it over to temporary redirect, 302 instead of 301.Just my two cents and soapbox here: Keep in mind if the folder /hello does not exist that is an http status code of "404 file not found" status. So, if you're intention is to do this for everything that doesn't exist then you might want to just redirect the 404 errors to your hello page otherwise scalability of making a bunch of rewrites to anticipate human behavior becomes a full-time job. Again, that's my two cents there.
ASKER
Also, how do I send someone to http://example.com/hello.php if they left off the extension and just typed http://example.com/hello
(and not generate an error)?