Question

how can I implement a custom 404 page

  • Posted January 26, 2015

Hello, I would like to ask about the best way to implement a custom 404 page. I had already found a small bit of help within the community about how to do this, but all seemed irrelevant. My issue is that I do not have a .htaccess file, and that I could build one, but even then, I do not know where to put it, and it is not the best solution anyhow. I read that I should instead use the httpd.conf file, but I do not have that file in my server either. What I have that I believe to be related are a localized-error-pages.con file, and a apache2.conf file. Should I be editing either one of these to include the ‘ErrorDocument 404’ line? Or is there a better way?

Subscribe
Share

Easiest way is with an .htaccess or a modification of your vhost configuration for apache. Something like this

You can either edit /etc/apache2/sites-enabled/000-default (Debian/Ubuntu) or /etc/httpd/conf/httpd.conf (Fedora/CentOS), and within the < VirtualHost > block, add this:

ErrorDocument 404 /notfound.html 

changing /notfound.html to the location of the custom 404 page

The other approach is taking the line above, adding it to an .htaccess file in the root of your website, and editing the files outlined above (000-default or httpd.conf), changing

AllowOverride None

to

AllowOverride All

Then restarting apache2/httpd


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

This question was answered by @JonsJava:

Easiest way is with an .htaccess or a modification of your vhost configuration for apache. Something like this

You can either edit /etc/apache2/sites-enabled/000-default (Debian/Ubuntu) or /etc/httpd/conf/httpd.conf (Fedora/CentOS), and within the < VirtualHost > block, add this:

ErrorDocument 404 /notfound.html 

changing /notfound.html to the location of the custom 404 page

The other approach is taking the line above, adding it to an .htaccess file in the root of your website, and editing the files outlined above (000-default or httpd.conf), changing

AllowOverride None

to

AllowOverride All

Then restarting apache2/httpd

View the original comment