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

1
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` 
1
  • @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. – iam batman Sep 19 '18 at 16:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.