A custom 404 page lets you provide a user-friendly website to your visitors even in the midst of an error. Very few users, when presented with a 404, will do more beyond click back to get out of the mistake. A custom 404 page is a good opportunity to keep them on your site and do more to redirect them to their destination.
Before going through this tutorial, you should already have created a custom 404 page and saved it into your website's directory.
To edit the 404 page, open up or create the site's .htaccess file. You can create it in a text editor and upload it to your site via the FTP server. Keep in mind that the name of the file has to be simply .htaccess.
Add the following line to the file, replacing new404.html with the correct new error page name:
ErrorDocument 404 /new404.html
Save and Exit.
Keep in mind that the Apache looks for the 404 page located within the site's server root. Meaning that if you place the new error page in a deeper subdirectory, you need to include that in the line, making into something like this:
ErrorDocument 404 /error_pages/new404.html
Now visiting unavailable pages on your site should display your custom 404 page!
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
It worked! Thx!
Where might I start troubleshooting the fact that this doesn’t work on my server? I created a 404.php then created a .htaccess file in /var/www/html/ which contains the following: ErrorDocument 404 /404.php
Yet, when navigating to any URL that does not exist on my website, I get the usual Apache 404 text.
Any thoughts?
I’m running Apache 2.4.7 courtesy of the DigitalOcean LAMP stack on Ubuntu 14.04
@bjurkowski: Try editing your virtualhost file (in
/etc/apache2/sites-enabled
) and settingAllowOverride
toAll
. Make sure you restart Apache afterwards:When I "sudo nano /etc/apache2/sites-enabled/default-000 it is blank and I am unable to edit anything. Not sure where my virtualhost file is. Any suggestions?
@dave: In newer versions of Ubuntu and Debian, the file is called
default-000.conf
:I installed the default LAMP config and I added this at the end of the file (outside of the </virtualhost> tag) <Directory /var/www/html/> Options Indexes FollowSymLinks AllowOverride All </Directory>
And it worked. Just adding AllowOverride All anywhere won’t work ;)
The .htaccess file is working but I am getting standard Apache “Page Not Found” Page, but I want to put my custom page
nice explanation Etel… thanks
Great method told this method is working for my site.
Thank you verryyy much !!