【发布时间】:2016-02-17 21:40:44
【问题描述】:
我正在尝试为我的网站编写一个像样的 .htaccess,但没有成功。
我的问题是我只想将某个页面重定向到另一个域的另一个页面。所有其他请求都必须重定向到 /other 域。
为了更清楚,我举个例子:
我只想重定向:
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 我不会被重定向。
我哪里错了?
【问题讨论】:
标签: apache .htaccess mod-rewrite