« transparent images using css with opacity | Main | Tableless form using HTML with CSS »

Redirecting 404 errors

Home » Programming » Mod_rewrite

we could redirect our users from a 404 error page not found to any url by editing our .htaccess files. this is usefull to give us more control in handling vairous html error codes. using the ErrorDocument tag and specifying the error code 404 as the page not found error code, (other error code might also be used in the redirect like: 400 - Bad Syntax, 401 - Unauthorized, 402 - Not used, 403 - Forbidden, 404 - Not Found, 500 - Internal Error, 501 - Not Implemented, 502 - Overloaded, 503 - Gateway Timeout).

Redirecting to an error page:

ErrorDocument 404 /404.html
- redirects the user to the 404.html page

using Rewrite to do the redirect:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.+) http://www.tildemark.com/404page/$1

or

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)testing\.html?$ temporary/$1

Display an html page:

ErrorDocument 404 <b>Page Not Found</b><p /><br /><a href="">Tildemark blogs homepage</a>

TrackBack

TrackBack URL for this entry:
http://www.tildemark.com/cgi-bin/mt/mt-tb.cgi/46

Comments (3)

Wait until you read this article that shows every single Apache Status Code and the actual headers and src returned from that error! Force Apache to output any HTTP Status Code with ErrorDocument

I setup an automated system to view all 57 Apache Response codes and ErrorDocuments, saving the headers and returned content for future reference. Use this page as a reference when designing scripts that use headers. Ex: 404 Not Found, 200 OK, 304 Not-Modified, 506 Service Temporarily Unavailable, etc.

When a Status code is encountered, Apache serves the header and the ErrorDocument for the error code. So if you can see any Header and ErrorDocument by causing that error on Apache.

For instance, if you request a file that doesn’t exist, a 404 Not Found is issued and the corresponding ErrorDocument is served with the 404 Not Found Header. So we can see what Apache 404 Errors and Response Codes look like, but how do we cause errors for the 56 other Apache Response Codes?

whoaaaa. that list is great! but isn't it too overkill? just didn't think of the other 56 error codes.

thanks anyway, this is indeed useful in my future venture with apache. :D

I live for overkill!

My whole blog is full of articles that are definately overkill. :p

About

This page contains a single entry from the blog posted on December 7, 2006 7:16 AM .

The previous post in this blog was transparent images using css with opacity .

The next post in this blog is Tableless form using HTML with CSS .

Many more can be found on the main index page or by looking through the archives .

Creative Commons License
This weblog is licensed under a Creative Commons License .
Powered by
Movable Type 3.33