2

I have an Apache 2 server and it have several vhosts with similar definition:

<VirtualHost *:80> DocumentRoot /var/www/html/host1/ ServerName host1.loc <Directory /var/www/html/host1> AllowOverride FileInfo Options AuthConfig </Directory> ErrorDocument 404 /index.php?error=404 </VirtualHost> <VirtualHost *:80> DocumentRoot /var/www/html/host2/ ServerName host2.loc <Directory /var/www/html/host2> AllowOverride FileInfo Options AuthConfig </Directory> ErrorDocument 404 /index.php?error=404 </VirtualHost> ... <VirtualHost *:80> DocumentRoot /var/www/html/hostN/ ServerName hostN.loc <Directory /var/www/html/hostN> AllowOverride FileInfo Options AuthConfig </Directory> ErrorDocument 404 /index.php?error=404 </VirtualHost> 

I would like to customize page 404.

The problem is that when I try to test 404 page in any of the hosts, I can see the page from the very last vhost. What could be wrong with my config?

8
  • What happens when you change it into a static message like ErrorDocument 404 "File not found on vhost hostN"? Do you get the right messages? Try placing the ErrorDocument directive inside of the Directory directive. Commented Dec 13, 2013 at 19:43
  • Could you update your post with at least two <virtualHost>...</virtualHost> directive you have ? Commented Dec 13, 2013 at 20:30
  • @dtech, it looks like there is no effect. It looks like this directive is completely ignored in every vhost except the very last one. Commented Dec 13, 2013 at 20:35
  • @user2196728, I added several more of them Commented Dec 13, 2013 at 20:38
  • 1
    "what about .htaccess ?" was planed to be my next question :) glad it works Commented Dec 13, 2013 at 21:27

2 Answers 2

2

Put ErrorDocument directives inside Directory tag.

Trunk: https://httpd.apache.org/docs/trunk/custom-error.html

2.2: https://httpd.apache.org/docs/2.2/mod/core.html#errordocument

Custom error documents are configured using the ErrorDocument directive, which may be used in global, virtualhost, or directory context. It may be used in .htaccess files if AllowOverride is set to FileInfo.

1
  • When triggering 404 via code, also make sure to manually include the 404 page, as the apache server does not do that on its own: stackoverflow.com/a/1381220/2126442 Commented Jul 25, 2019 at 12:16
-4

Use an html file instead of php one.

ErrorDocument 404 /custom_error_404.html 
1
  • 2
    I am quite sure a php file can be used for custom 404...or other Commented Dec 13, 2013 at 19:39

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.