【问题标题】:.htaccess - redirect to specific page + redirect to /.htaccess - 重定向到特定页面 + 重定向到 /
【发布时间】: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


    【解决方案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]
    

    【讨论】:

    • @Simone Giusti:抱歉,请重试我上面的 .htaccess。它现在应该可以工作了。
    • @SimoneGiusti :我测试了我在上面编辑的那个,它工作得很好。请尝试一下,让我知道仍然无法使其工作。
    • @SimoneGiusti:我还发布了您的真实 .htaccess,经过更正并再次测试:)
    猜你喜欢
    • 2019-01-15
    • 2017-08-16
    • 1970-01-01
    • 2012-10-29
    • 2021-08-18
    • 1970-01-01
    • 2017-12-26
    • 2012-03-26
    • 2012-06-19
    相关资源
    最近更新 更多