Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

301 Redirect for all pages to new site Except 1 directory

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...

like image 202
Tom Avatar asked May 24 '13 06:05

Tom


People also ask

Can I 301 redirect from one domain to another?

A 301 redirect is a permanent redirect from one URL to another. While they can redirect site page URLs, they can also redirect from one domain to another.

Would it be necessary to 301 redirect every page on a site?

301 redirects should be used when a page is no longer relevant, useful or has been removed. They are also really valuable for site rebuilds, where URLs are tidied up into the newer, cleaner pages. It is very important to redirect any old URLs that won't be staying the same on a rebuild of your website.

Why does 301 redirect not work?

The reasons for 301 redirect not working are much more well-defined among WordPress sites. One of the main causes is because you have added the rewrite rules on both the cPanel “Redirects” tool and from your WordPress plugin.


1 Answers

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/store
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]
like image 101
claustrofob Avatar answered Oct 23 '22 08:10

claustrofob