How do I use htaccess to redirect a bunch IPs to a text file on my server?
October 26, 2006 1:30 PM
Subscribe
Using htaccess, I'd like to redirect all requests from a random set of IPs to a text file explaining that the IP has been banned. What would be the easiest and most efficient way to do this?
I'm trying to stop splogs and comment spammers from ever reaching my server. I know I can simply block them using deny, allow rules, but I don't want to just block -- I want potential innocents to be directed to a note just in case I get overzealous in my blocking.
posted by maxpower to computers & internet (5 comments total)
<Directory /docroot>
RewriteEngine on
RewriteCond %{REMOTE_ADDR} 10\.0\.0\.3
RewriteRule ^index.html$ special_index.html [L]
</Directory>
Mind you, this would be used in an httpd.conf file, so in a .htaccess file, you remove the <Directory> tags. The IP address is a regular expression, so you could append the multiple addresses in that line; alternatively, you could use the "[OR]" flag:
RewriteCond %{REMOTE_ADDR} 192\.168\.0\.1 [OR]
RewriteCond %{REMOTE_ADDR} 192\.168\.10\.5 [OR]
RewriteCond %{REMOTE_ADDR} 192\.168\.100\.50
RewriteRule ^index.html$ special_index.html [L]
posted by bachelor#3 at 3:50 PM on October 26, 2006