Forum Moderators: phranque

Message Too Old, No Replies

Need help with a rewrite rule for http301

         

ForumKid1

5:23 pm on Dec 14, 2010 (gmt 0)

10+ Year Member



I have a situation where I have a website with the following structure.

Site: www.xyz.com
Folders:
www.xyz.com/site/folder1
www.xyz.com/site/folder2
www.xyz.com/site/folder3...and so on.

My current apache redirect redirects the entire www.xyz.com to www.newsite.com as such:
RewriteRule ^/$ http://www.newsite.com/newsite/ [R=301,L]

What I want to do is this. I want to redirect the entire site of www.zyx.com to www.newsite.com EXCEPT www.xyz.com/site/folder2. The only way i know how to do it is with explicit redirects for each folder. I feel there is a better approach (like using a not equal to or something similar) that can be done with one redirect, but I'm not able to get it to work. Just wondering if anyone can point me in the right direction.

g1smd

7:41 pm on Dec 14, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Firstly, the above rule does not redirect the "entire site". It redirects only root requests.

To redirect "everything" change the pattern from ^/$ to (.*) and to then not redirect folder2 add this code before the modified rule:

RewriteCond {%REQUEST_URI} !^/folder2/ 


Add $1 to the end of the redirect target URL to preserve the original folder and page request.

ForumKid1

12:16 pm on Dec 16, 2010 (gmt 0)

10+ Year Member



Thanks so much for your help. Works like a charm.