Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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]
share|improve this question
    
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 Answer 1

This is untested but try this for the remote_addr part

RewriteCond %{REMOTE_ADDR} !=1.2.3.4
share|improve this answer
    
Unfortunately result is the same: site1 also redirects 1.2.3.4 to site2 –  ijujym Aug 30 '12 at 16:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.