【问题标题】:http 301 redirect from htaccess to domain hosthttp 301 从 htaccess 重定向到域名主机
【发布时间】:2011-01-30 10:05:41
【问题描述】:

我在 .htaccess 文件中有以下内容

redirect 301 /page.php http://domain.com/page

效果很好并且符合预期。

我希望能够重定向以下内容

http://domain2.com/page.php to http://domain2.com/page
or
http://domain3.com/page.php to http://domain3.com/page
or
http://domain4.com/page.php to http://domain4.com/page

所以基本上无论域名是什么,我都想重定向到它。但问题是我想使用 301 重定向。这甚至可能吗?或者我应该使用 RewriteCond 和 RewriteRule 吗?

【问题讨论】:

    标签: apache .htaccess url-rewriting


    【解决方案1】:

    我认为仅 RewriteRule 就足够了:

    RewriteRule ^/page\.php$ /page [R=301,L]
    

    这将导致对page.php 的任何请求被重定向到同一域上的pageR=301 导致使用 301 重定向。

    【讨论】:

    • “L”停止处理其他规则。我不确定在使用“R”时是否有必要,但它不会造成伤害。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-17
    • 1970-01-01
    • 1970-01-01
    • 2012-09-23
    • 1970-01-01
    • 2013-09-23
    • 1970-01-01
    相关资源
    最近更新 更多