Hi,
Recently I’ve been looking at the recent visitor stats for my site and saw that there were a few 404s, probably from moved assets or something but the default 404 for Hostgator (my hosting company) is an ugly looking page. I wanted to change this so went into the cpanel backend and went to the “Error Pages” page to setup a 404. However this doesn’t actually work. After some looking around I found that it is fairly simple to setup myself. I just need to add the line to the .htaccess on my www webroot. The .htaccess file is extremely useful as you can setup other error pages using the same technique. The format is as follows
ErrorDocument ErrorNumber /ErrorPage
So to setup a 404 I entered the line below into my .htaccess file
ErrorDocument 404 /404.php
Setting up custom 404s is useful as you can just provide a graceful error and provide something useful back to a user(including your own headers, footers and styling) rather than an ugly server/hosting supplied page.
Possible error types that can be setup as listed below.
401 – Authorization Required
400 – Bad request
403 – Forbidden
500 – Internal Server Error
404 – Wrong page
HTAccess can also be used to deny certain ip addresses:
deny from 000.000.000.000
Finally the HTAcess file can be used to perform redirects:
Redirect /FromPage.php /ToPage.php
