301将所有页面重定向到新站点除1个目录外

时间:2013-05-24 06:22:50

标签: apache .htaccess http-redirect

我正在尝试为所有网页创建301重定向,但只有一个目录到新网站,但我无法设置它。

这基本上就是我所需要的:

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/

我试过这个方法:

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

但是当我转到http://www.example.com/store时,我需要http://www.newdomain.com/store

基本上我需要目录/存储保留在旧域上。有人可以帮忙吗?不熟悉.htaccess规则......

1 个答案:

答案 0 :(得分:20)

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