3

I'm trying to write a custom redirect rule for some testing purposes on 2 domains with exactly same site. The code I am using is:

  RewriteEngine on
  RewriteCond %{REMOTE_ADDR} !^1\.2\.3\.4$
  RewriteCond %{HTTP_HOST} ^.*site1.com [NC]
  RewriteRule ^(.*)$ http://www.site2.com/$1 [R=301,L]

What I want is to redirect all requests for site1 to site2 except for requests from IP address 1.2.3.4. But currently requests from that IP are also being redirected to site2.

Is there something I've missed in settings?

( note: both domains are on the same shared hosting account )

EDIT: I'v also tried:

RewriteEngine on
  RewriteCond %{REMOTE_ADDR} !^my_ip$ [OR]
  RewriteCond %{REMOTE_ADDR} !^server_ip$
  RewriteCond %{HTTP_HOST} ^.*site1 [NC]
  RewriteRule ^(.*)$ http://site2/$1 [R=301,L]

RewriteEngine on
  RewriteCond %{REMOTE_ADDR} !=my_ip [OR]
  RewriteCond %{REMOTE_ADDR} !=server_ip
  RewriteCond %{HTTP_HOST} ^.*site1 [NC]
  RewriteRule ^(.*)$ http://site2/$1 [R=301,L]

RewriteEngine on
  RewriteCond %{REMOTE_ADDR} ^my_ip$ [OR]
  RewriteCond %{REMOTE_ADDR} ^server_ip$
  RewriteRule ^(.*)$ http://site1/$1 [L]

  RewriteCond %{HTTP_HOST} ^.*site1 [NC]
  RewriteRule ^(.*)$ http://site2/$1 [R=301,L]
Dan R
  • 2,275
  • 1
  • 19
  • 27
ijujym
  • 131
  • 3
  • Are you sure about what IP address your sever sees for `%{REMOTE_ADDR}`? This condition reads if REMOTE_ADDR is NOT = 1.2.3.4 AND HTTP_HOST is site1.com, redirect to site2.com. Therefore IP address 1.2.3.4 should not get redirected. – HeatfanJohn Aug 30 '12 at 13:41
  • Yes, the IP look up tools show that the IP is correct. And I do want that every one would be redirected from site1->site2 except visitors from our office IP so they can see the site1. Well if the statement is correct than I will double check this with our hosting support, Thanks – ijujym Aug 30 '12 at 14:58

1 Answers1

0

This is untested but try this for the remote_addr part

RewriteCond %{REMOTE_ADDR} !=1.2.3.4
Mike
  • 21,910
  • 7
  • 55
  • 79