Page 1 of 1

Redirect a block of Ip addresses

Posted: Sun Oct 02, 2011 9:34 am
by dom44

I'm am trying to block a group of IP addresses from my store and I have been searching the forum for some instructions on how to do this. I've come across the htaccess deny access method but I'm trying to modify this so visitors from that IP range do not get a "forbidden page" but rather are redirected to for example contactus.html .

Could anyone tell me how I could do this?

Thank you very much in advance.

Re: Redirect a block of Ip addresses

Posted: Mon Oct 03, 2011 3:44 am
by uksitebuilder
In .htaccess

after RewriteBase / line

Code: Select all

RewriteCond %{REMOTE_HOST} 123\.456\.789\.123
RewriteCond %{REMOTE_HOST} 123\.456\.789\.123
RewriteCond %{REMOTE_HOST} 123\.456\.789\.123
RewriteRule .* /index.php?route=information/contact [R=301,L]
repeat the RewriteCond line for as many IP's you want to do this for

Note, you must escape the periods (dots) in the ip address with a backslash as per example above

Re: Redirect a block of Ip addresses

Posted: Tue Oct 04, 2011 5:54 am
by dom44
Thanks Simon for helping me out.

I used the code you provided and now my .htaccess file looks like this:

Code: Select all

RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_HOST} 123\.123\.123\.123
RewriteRule .* /ip.html [R=301,L]
I tested it out with my ip address but it doesn't seem to be working. Am I missing anything? Perhaps something before RewriteEngine On or after the code?

Thank you for your help.