.htaccess - 重定向到特定页面+重定向到/

时间:2016-02-17 21:40:45

标签: apache .htaccess mod-rewrite

我试图为我的网站写一个体面的.htaccess,但没有成功。

我的问题是我想只将某个页面重定向到另一个域的另一个页面。所有其他请求必须重定向到/ other domain。

我举一个更清晰的例子:

我只想重定向:

www.foo.com/test_a.php => www.bar.com/newcategory/newpage
www.foo.com/another_page.php => www.bar.com/anothernewcategory/anothernewpage

所有其他请求必须重定向到www.bar.com

示例:

www.foo.com/some_another_page_not_listed_above => www.bar.com

这是我的.htaccess,但它不起作用:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^/test_a.php
RewriteRule www.bar.com/newcategory/newpage/ [NC,L,R=301]

RewriteCond %{HTTP_HOST} ^/another_page.php 
RewriteRule www.bar.com/anothernewcategory/anothernewpage/ [NC,L,R=301]

RewriteCond %{HTTP_HOST} ^/  
RewriteRule https://www.bar.com/ [L,R=301]

规则1和2有效。规则3没有。例如,如果我访问www.foo.com/test_page,我就不会被重定向。

哪里错了?

1 个答案:

答案 0 :(得分:1)

你能试试吗?

RewriteEngine On
RewriteRule  ^test_a.php http://www.bar.com/newcategory/newpage/ [NC,L,R=301]
RewriteRule ^another_page.php http://www.bar.com/anothernewcategory/anothernewpage/ [NC,L,R=301]
RewriteRule ^ https://bar.com [L,R=301]
相关问题