I understand how to ban an IPs address from my apache webserver using .htaccess:
order allow,deny
deny from 192.168.44.201
deny from 224.39.163.12
deny from 172.16.7.92
allow from all
I’d like to create a custom “You’ve been banned” page. How could I do this?
EDIT:
To clarify, I am not trying to create a custom 403 page, as these are used in other instances as well (i.e. failed basic authentication, etc). The closest I have come so far is:
rewritecond %{REMOTE_ADDR} ^127\.0\.0\.1$
RewriteRule !^banned$ /banned [NC,L]
but this produces an internal server error when the IP is matched, instead of sending the user to /banned
The other answers which suggest an
ErrorDocumentfor the 403 code would be the usual way to do this. But since you want to show a different error page if the user is denied access based on IP (as opposed to other reasons), you can use mod_rewrite, as you suspected.P.S. This should go in your virtual host configuration, not an
.htaccessfile, if at all possible. If you don’t have access to the virtual host configuration file, you could put it in a.htaccessfile, but remove the leading slash from theRewriteRulepattern (so!^/banned.htmlbecomes!^banned.html).