I want to whitelist one IP for a site I've set up in a virtualhost file. Within the <VirtualHost> section, I've set these 2 basic rules:

ErrorDocument 403 /var/www/html/403.html
<Location />
    Require ip xxx.xxx.xxx.xxx

When I access the site outside the allowed IP, I get the generic Apache "Forbidden" page instead of the custom one I'm trying to use. I even get the extra message "Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request." It kinda makes sense since I'm not allowing access to any URL to disallowed IP's, but obviously I'd like to make one exception to view my custom 403 page.

FWIW within the VirtualHost, DocumentRoot has already been set within /var/www/vhosts/blahblah so I figured /var/www/html/403.html would not be restricted. I've seen some form of this question asked on this site and others, but no one seems to have a real working solution, especially for 2.4 - any Apache engineers present? =]


Either exclude the Location containing the error page from the Location / directive denying access by preceding that with a

  <Location/403.html  >
         Require all granted

Or ensure that the error document is outside the Location / that is denied by using a different (sub) domain to present the error

I.e. use something like :

 ErrorDocument 403 https://errors.example.com/403.html

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.