.htaccess: Set custom 404 error page

Apache allows you to customize the server at the directory level, using .htaccess files. Below how to use them to serve custom 404 error (page not found), and other common error pages, to your users.

Alternately, You can place the 404 error template anywhere you want in a folder. For example you could place all error messages in a folder called “errormsg” refererring the 404 error to the url of the page.

[php toolbar=”false” classname=”one_line”] ErrorDocument 404 /errormsg/404.php [/php]

Also you can customize these directives a great deal. For example, you can add directives for any of the status codes below, to show custom pages for any error the server may report. You can also, if you want, specify a full URL instead of a relative one. And if you are truly adventurous, you could even use pure HTML in the .htaccess file to be displayed in case of an error, as below. Note that if you want to use HTML, you must start the HTML with a quotation mark, however you should not put one at the other end of the HTML (you can include quotation marks within the HTML itself as normal).

[php toolbar=”false” classname=”one_line”] ErrorDocument 404 "Ooops, that page was <b>not found</b>. Please try a different one or <a>email the site owner</a> for assistance.

Leave A Comment