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

1 Answer 1

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> 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.