Monday, May 14, 2012

ErrorDocument 404 with .htaccess

In order to setup custom 404 page, and prevent user from viewing default error page, you can use ErrorDocument 404 in htaccess. Just copy/paste following snippet into your .htaccess file:

ErrorDocument 404 /pages/errorDocument/error404.php
 

More about ErrorDocument directive

ErrorDocument directive doesn’t have to be used only for errors 404, and it can do couple of things except from redirecting your visitor. Using ErrorDocument directive, you can redirect users to another website, as well as print custom message to the user.

Syntax Example :

ErrorDocument error-code some-error-document-file
Here is a snippet with ErrorDocument examples:

ErrorDocument 500 http://example.com/
ErrorDocument 404 /pages/errorDocument/error404.php
ErrorDocument 403 "You are forbidden to access this page!"


No comments:

Post a Comment