Page 1 of 1

htaccess infinite loop problem

Posted: Tue Oct 04, 2011 11:13 am
by dom44
Hi,

I'm am trying to block a group of IP addresses from my store but I don't want to visitor to see a "forbidden page" but rather a "contact us" page.

I did some googling and got some help from this forum and came up with this to put in my .htaccess file:

Code: Select all

Options +FollowSymlinks 
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_ADDR} ^(123\.123\.123\.123)$
RewriteRule ^/* contactus.html [R=301,L]
Right now I am testing it with my own IP address and since contactus.html is in the same directory it is also getting blocked and it is causing an infinite loop.

Besides setting the redirect to another website, is there anyway to solve this problem?

Any help would be greatly appreciated.

Thank you

Re: htaccess infinite loop problem

Posted: Tue Oct 04, 2011 3:15 pm
by uksitebuilder
the following should work

Code: Select all

RewriteCond %{REMOTE_HOST} ^123\.45\.67\.89
RewriteCond %{REQUEST_URI} !/contactus\.html$
RewriteRule \.html$ /contactus.html [R=302,L]
The 2nd line excludes that page so in theory should stop the redirect loop you were getting

Re: htaccess infinite loop problem [Solved]

Posted: Thu Oct 06, 2011 12:45 pm
by dom44
Thanks Simon for all the help.

For some reason I could not get your exact code to work, but I blended it with the old code I had and got it to work.

For those of you'll who have the same problem, this is the code that worked for me:

Code: Select all

Options +FollowSymlinks 
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_ADDR} ^(123\.45\.67\.89)$	
RewriteCond %{REQUEST_URI} !/contactus\.html
RewriteRule .* /contactus.html