301重定向,但异常不起作用

时间:2012-11-26 15:58:57

标签: .htaccess redirect http-status-code-301

我现在真的很难受,所以不胜感激。

我正在尝试将网站重定向到另一个域,但有一些例外。这是我现在在.htaccess文件中的代码

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !/sitemap/
RewriteCond %{REQUEST_URI} !/contact-us/
RewriteRule ^.*$ http://www.newsite.com/folder/$0 [R=301,L]

Redirect 301 /sitemap/ http://www.newsite.com/sitemap/
Redirect 301 /contact-us/ http://www.newsite.com/contact-us/

为什么这可能不起作用的任何想法?

主页和站点地图以及联系我们页面重定向正常,但所有其他页面都没有重定向。

提前致谢。

1 个答案:

答案 0 :(得分:0)

将重定向线移到更高

RewriteEngine On
Redirect 301 /sitemap/ http://www.newsite.com/sitemap/
Redirect 301 /contact-us/ http://www.newsite.com/contact-us/
RewriteBase /
RewriteCond %{REQUEST_URI} !/sitemap/
RewriteCond %{REQUEST_URI} !/contact-us/
RewriteRule ^.*$ http://www.newsite.com/folder/$0 [R=301,L]

我在我的apache服务器上尝试了这个并且它有效

http://www.oldsite.com/sitemap/ => http://www.newsite.com/sitemap/
http://www.oldsite.com/contact-us/ => http://www.newsite.com/contact-us/
http://www.oldsite.com/test => http://www.newsite.com/folder/test