301 Redirect for all pages to new site Except 1 directory

Tom picture Tom · May 24, 2013 · Viewed 16.8k times · Source

Im trying to create a 301 redirect for all pages but one directory to a new site, but Im having trouble setting it up.

This is basically what I need:

http://www.example.com/store => no redirects, users remain on http://www.example.com/store
http://www.example.com/* => all other pages go to this url http://www.newdomain.com/

AKA

http://www.example.com/apple => http://www.newdomain.com/
http://www.example.com/pie => http://www.newdomain.com/
http://www.example.com/foo/bar => http://www.newdomain.com/

I tried this method:

RewriteEngine on
RewriteCond %{REQUEST_URI}!^/store/
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]

But when I go to http://www.example.com/store it takes me to http://www.newdomain.com/store

Basically I need the directory /store to remain on the old domain. Can anyone help? Not to experienced with .htaccess rules...

Answer

claustrofob picture claustrofob · May 24, 2013
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/store
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]