0

This is a continuation of my other post: Catch all VirtualHost not working.

I have got the catchall VirtualHost working. But know how do I get it to redirect a custom error page such as 404.

In my VirtualHost I add Redirect 404 /, it takes me to the default 404 page. But when I enable ErrorDocument 404 /errors/index.php I get the following error

Not Found

The requested URL / was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

Below is my catchall config

<VirtualHost *:80>
    DocumentRoot /var/www/main
    ServerName null

    Redirect 404 /
    ErrorDocument 404 /errors/index.php

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>
  • Duplication of https://serverfault.com/questions/775570/apache-2-4-errordocument-for-multiple-subdomains/999619#999619 See answer https://serverfault.com/a/999619/174375 – Thomas Lauria Jan 20 '20 at 09:12

1 Answers1

0

That's because your Redirect 404 / affects even when trying to access /errors/index.php.

When giving 404 Not Found, you don't need to redirect everything to the root. I would suggest giving the human readable error message for non-existing virtual host at / i.e. /index.html as a normal 200 OK and use ErrorDocument 404 / to give the same content as 404 for all other URLs. The location doesn't need to change when you have already given 404 Not Found.

<VirtualHost *:80>
    ServerName null

    DocumentRoot /var/www/main
    ErrorDocument 404 /

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Esa Jokinen
  • 46,944
  • 3
  • 83
  • 129