Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have In my web root /home/www/ I have an .htaccess file to ban IP addresses:

order allow,deny
deny from
deny from
allow from all

ErrorDocument 500 /errors/500.htm
ErrorDocument 403 /errors/403.htm

I have also tried it this way with the error statements:

ErrorDocument 500 /home/www/errors/500.htm
ErrorDocument 403 /home/www/errors/403.htm

I have created an error directory, /home/www/errors which contains the following files:


In the errors directory .htaccess I have set the rules:

order deny,allow
allow from all

If I put my IP in the root .htaccess file I can't browse the site. I get an error:

Forbidden - You don't have permission to access / on this server.

Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.

However if I browse to /errors/500.htm I can see that page in my browser, so I know the subdirectory .htaccess seems to allow those files to be loaded.

What am I doing wrong? How can I deny from a certain IP address but still show a custom error page with Apache2?

share|improve this question
up vote 1 down vote accepted

it would be much easier to simply redirect people coming from the blocked IPs to an error page:

RewriteCond %{REMOTE_ADDR}
RewriteRule .* /CustomError.html [R=403]
share|improve this answer
Good enough. Thanks. – cwd Nov 1 '12 at 16:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.