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

I'm dying on this htaccess:

RewriteCond %{HTTP_HOST} ^[www\.]?old\.com [NC]  
RewriteCond %{REQUEST_URI} ^.+$  
RewriteCond %{REQUEST_URI} !^wp-admin  
RewriteCond %{REQUEST_URI} !^index  
RewriteCond %{REQUEST_URI} !^subdomain  
RewriteRule ^(.*)$ http://www.new.com/%{REQUEST_URI} [R=301,L]  

I'm trying to redirect all traffic from www.old.com to www.new.com EXCEPT when they access:

www.old.com
old.com
old.com/wp-admin
old.com/subdomain

I still want the old site to show up and be able to administer it, but any old.com/something should be redirected to new.com/something.

That's the other thing, I couldn't get this to work by using $1 as a backreference. I had to hard-code the %{REQUEST_URI} in there instead (which worked).

The last exmaple (old.com/subdomain) is a second website entirely and I don't want to interfere with its operation either.

I've read so, so many websites and every variation makes perfect sense from a regular expression point of view and they all should work, but they don't. This is driving me crazy.

share|improve this question

migrated from stackoverflow.com Apr 10 '11 at 20:23

This question came from our site for professional and enthusiast programmers.

1 Answer 1

Try these rules in your .htaccess:

RewriteCond %{HTTP_HOST} ^(www\.)?old\.com$ [NC]  
RewriteCond %{REQUEST_URI} !^/?(wp-admin|index|subdomain) [NC]
RewriteRule ^(.+)$ http://www.new.com/$1 [R=301,L,QSA,NE]

Let me know if it doesn't work.

share|improve this answer
    
No change of any kind. Also I want to be able to visit www.old.com and see the parked page I put there while only redirecting to the new when they try to access www.new.com/anything_except_wpadmin_or_index.php –  user77914 Apr 10 '11 at 22:46
    
@user77914: I made a minor correction, please try again. Also if you notice I am only redirecting .+ which means http://www.old.com will NOT be redirected to http://www.new.com. –  anubhava Apr 10 '11 at 23:48
    
It still redirects all requests for old.com to new.com. I'm starting to think there's some other issue at hand here, but I've commented out nearly every other line in the file except for RewriteEngine on, RewriteBase /, Options +FollowSymLinks, and the few lines Wordpress adds for pretty permalinks. –  user77914 Apr 11 '11 at 1:16
    
Just for testing comment both the RewriteCond lines and have your RewriteRule like this RewriteRule ^(wp-admin)$ http://www.new.com/$1 [R=301,L,QSA,NE] . That should start redirecting ONLY wp-admin but leave everything else as is. –  anubhava Apr 11 '11 at 11:56

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.