0

I am trying to set up a custom error page for 404 error on my apache server.

Here is what I am included in the Virtualhost

<VirtualHost *:80>
   ErrorDocument 404 /var/www/html/mant.html
</VirtualHost>

But this page is not showing instead its redirect to default 404 page

Note:

I've restarted the apache with sudo service apache2 restart

I am able to access the error page with the following url

<ip>/mant.html

shellakkshellu
  • 115
  • 2
  • 8
  • what are permission of this page ? Please check - https://www.digitalocean.com/community/tutorials/how-to-configure-apache-to-use-custom-error-pages-on-ubuntu-14-04 – sanjayparmar Sep 19 '18 at 05:43

1 Answers1

5

Your current configuration expects the custom error page to be found on http://www.example.com/var/www/html/mant.html.

The path to the ErrorDocument is an URL path, either relative to your DocumentRoot:

<VirtualHost *:80>
   DocumentRoot /var/www/html/
   ErrorDocument 404 /mant.html
</VirtualHost>

or an absolute URL such as:

<VirtualHost *:80>
   DocumentRoot /var/www/html/
   ErrorDocument 404 http://www.example.com/mant.html
</VirtualHost>

it is not a path on your file-system.


Edit: Based on your comment

The problem is the document root folder is deleted once the build starts so at that time someone try to access it should return the 404 error page.

Then store your error pages outside of the DocumentRoot where they won't be deleted:

 Alias /errors/ /var/www/errors/
 ErrorDocument 404 /errors/404.html` 
HBruijn
  • 72,524
  • 21
  • 127
  • 192
  • @HBrujin the problem is the document root folder is deleted once the build starts so at that time someone tries to access it should return the 404 error page. – shellakkshellu Sep 19 '18 at 16:08