Allowing blocked IP to view 403 ErrorDocument
-
17-12-2020 - |
Вопрос
I have a script that is automatically adding IP addresses to my.htaccess file based on lookups in spam databases. However, I would like for subsequent visits from those addresses to be able to view a 403 ErrorDocument I create. Obviously, though, they cannot, as they have been denied. My .htaccess looks like this:
ErrorDocument 403 /403.php
deny from <ip address>
deny from <ip address>
deny from <ip address>
deny from <ip address>
yada yada yada
Any suggestions on how to do this? I am adding the addresses via PHP.
Thanks in advance.
Решение
You have two way:
- ErrorDocument 403 http://www.yourdomain.com/403.php
- ErrorDocument 403 "Go and Do NOT return!"
of course, First one will redirect user!
If you have particular file formats on your site(like .php,.txt,.xml,.htm,...) you can use this one but I DO NOT recommend it!
<Files ~ "\.(inc|sql|.php|.html)$">
order allow,deny
allow from all
deny from 127.0.0.1
</Files>
Update:
As Sean Kimball
mentioned you can use rewrite mod (of course it's possible,it's Apache)
RewriteCond %{REMOTE_ADDR} ^127\.0\.0\.1$
RewriteRule (.*) 403.php
Другие советы
I would think a rewrite rule would be more appropriate - though I'm not 100% sure you can redirect based on an ip address. You would need to check the mod_rewrite docs.