Linux: .htaccess and custom error messages

When we create a domain and would like to have custom error messages for the sites that we build .htaccess file comes in handy.

There may be errors related to site access sucha as 401 – Unauthorized access, 404 – Document Not Found, 500 – Internal Server Error. To handle such error you can create a separate folder called “errors” for the site which will have the files error401.html, error404.html, error500.html each bearing the custom messages that you would like to have it published via the web.

Then, add the following lines of code to .htaccess

ErrorDocument 401 /error401.html
ErrorDocument 404 /error404.html
ErrorDocument 500 /error500.html

Restart the server and we are good to go

user@myhost:~# sudo /etc/init.d/apache2 restart