Specifying your own error pages with .htaccess

05.03.2013 by Ilia Raiskin
htaccess UX Quick

In this quick tip we are going to specify our own error pages with the .htaccess file. Usually when a user tries to open a page on a website that doesn't exist, he gets a standart error message from the server. If you want to create your own error page (PHP/HTML...), and then display it when a user tries to open a file that doesn't exist, you can set that easily with the .htaccess file. The only thing you need is an own error page which you saved on your website-server. Please note that error pages should be designed to easily help visitors, so an error page should be kept short and "clean". Here is an example of an error page:

After saving this (or your own) file on the server, you can add this to your .htaccess file:


ErrorDocument *** /errors/test.php


The stars have to be replaced by the matching HTTP Status code. For example 404 is the code of "page not found". errors is the name of the folder where the error files are saved (of course you can save the error files wherever you want). You can replace test.php with any other file. You can use this rule multiple times, if you also want to set your own error pages for other HTTP Status codes. Read more about HTTP Status codes.

This is how the code looks for HTTP Status code 404.


ErrorDocument 404 /errors/404.php


About the author

Ilia Raiskin

Ilia Raiskin is a web designer, web developer, blogger and founder of Toolinfy.com.






Comment