I learn how to prohibit an Insolvency practitioners address from the apache webserver using .htaccess:

order allow,deny
deny from
deny from
deny from
allow from all

Let me produce a custom "You have been banned" page. How could I actually do this?


To explain, I'm not trying to produce a custom 403 page, because these are utilized in other instances too (i.e. unsuccessful fundamental authentication, etc). The nearest I've come to date is:

rewritecond %{REMOTE_ADDR} ^127\.0\.0\.1$
RewriteRule !^banned$ /banned [NC,L]

but this produces an interior server error once the IP is matched up, rather than delivering the consumer to /banned

Another solutions which suggest an ErrorDocument for that 403 code will be the usual method of doing this. Consider you need to show another error page when the user is refused access according to IP (instead of some other reasons), you should use mod_rewrite, while you suspected.

RewriteCond %{REMOTE_ADDR} = [OR]
RewriteCond %{REMOTE_ADDR} = [OR]
RewriteCond %{REMOTE_ADDR} =
RewriteRule !^/banned.html /banned.html [L]

P.S. This will use your virtual host configuration, no .htaccess file, if whatsoever possible. Without having accessibility virtual host configuration file, you can place it inside a .htaccess file, but take away the leading slash in the RewriteRule pattern (so !^/banned.html becomes !^banned.html).

You utilize an ErrorDocument directive. People who are refused access are sent a 403 header, so:

ErrorDocument 403 banned.html

will redirect banned individuals to banned.html

Edit: Another alternative would be to drop the mod_access stuff altogether, and employ an IP-based rewrite rule (as pointed out within the question). It will you need to be:

RewriteEngine on
RewriteCond %{REMOTE_ADDR} [OR]
RewriteCond %{REMOTE_ADDR} [OR]
RewriteCond %{REMOTE_ADDR}
RewrulteRule .* banned.html [L]

Edit 2: David beat me for an almost identical answer I believe his way is what you would like

Inside your .htaccess file:

ErrorDocument 403 /banned.html 

change /banned.html to whatever path/to/filename you would like.