A tutorial to enable custom error pages with an htaccess file. Note htaccess files only work on a linux server
To create an htaccess file open notepad or any plain text editor and save the file as .htaccess, if using notepad make sure the file type is set to all files or you will create a txt file.
There are five types of error pages that your server has to offer which are:
400 - Bad request
401 - Authorization Required
403 - Forbidden directory
404 - Page not found
500 - Internal Server Error
if you don't have the right page like say a 404 page then the server issues you the error and informs you it could not find an error document. Making your own custom error page is very easy with htaccess on an htaccess file enter the command ErrorDocument then the error number then a forward slash then the path to the error page which tells the page where to go like this:
ErrorDocument 404 /errors/404.php
The final file will look like this:
ErrorDocument 400 /400.html ErrorDocument 401 /401.html ErrorDocument 403 /403.html ErrorDocument 404 /404.html ErrorDocument 500 /500.html
Save the htaccess file in the root of the server then if their is an error the custom error page is served.
For the past 12 years, I’ve been developing applications for the web using mostly PHP. I do this for a living and love what I do as every day there is something new and exciting to learn.
In my spare time, the web development community is a big part of my life. Whether managing online programming groups and blogs or attending a conference, I find keeping involved helps me stay up to date. This is also my chance to give back to the community that helped me get started, a place I am proud to be apart of.
Besides programming I love spending time with friends and family and can often be found together going out catching the latest movie, staying in playing games on the sofa or planning a trip to someplace I’ve never been before.