Wednesday, 3 January 2018

How to Make a Custom 404 Error File

I guess different servers do 404 error files different ways. I am working on an Apache server, so that is what we will be covering here.
Create a custom HTML error File
This part is simple, use regular old HTML along with some CSS style to create a normal web page with whatever content you'd like users to see when encountering a 404, file not found error on your web site. For the purpose of this tutorial, you could simply copy and paste the following line into a file and name it custom404.html:
ERROR: No file found! Please try again.
Of course, feel free to use all HTML markup and CSS you like, but for demonstration purposes, the above line of text will work just fine as well.

Edit the .htaccess File

You can find a file named .htaccess in your root directory and if not, just create a new file and name it .htaccess. Note that .htaccess is a file extension and should have a dot in front of it. It's like a file without a name basically using the .htaccess extension. Weird, I know, but that's how it's done. Also be careful if you use notepad because it will try to append .txt to the file name and it won't work like that, so if you have that issue, try entering ".htaccess" with the quotes when saving the file and it should understand. So whether you found the .htaccess file or had to create a fresh one, simply append this to the end of your file and save as I just described:
ErrorDocument 404 /custom404.html
Then upload your custom404.html file to the servers web root directory and you are done! If it doesn't work, try restarting the server before moving on to the next method.

0 comments:

Post a Comment