Jv
By:
Jv

how can I implement a custom 404 page

January 26, 2015 690 views

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?

1 comment
  • 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

1 Answer

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

Have another answer? Share your knowledge.