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?

  • 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. – dtech Dec 13 '13 at 19:43
  • Could you update your post with at least two <virtualHost>...</virtualHost> directive you have ? – krisFR Dec 13 '13 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. – Antonio Dec 13 '13 at 20:35
  • @user2196728, I added several more of them – Antonio Dec 13 '13 at 20:38
  • 1
    "what about .htaccess ?" was planed to be my next question :) glad it works – krisFR Dec 13 '13 at 21:27
1

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.

| improve this answer | |
-4

Use an html file instead of php one.

ErrorDocument 404 /custom_error_404.html
| improve this answer | |
  • 2
    I am quite sure a php file can be used for custom 404...or other – krisFR Dec 13 '13 at 19:39

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.