【问题标题】:Htaccess: redirect some pages from one domen to anotherHtaccess:将一些页面从一个域重定向到另一个域
【发布时间】:2016-10-13 08:04:08
【问题描述】:

我需要将一些页面从一个圆顶重定向到另一个。例子: example.com/help/questions(/show/some_text|none|get params)example2.com/questions(/show/some_text|none|get params)

htaccess:

Redirect permanent /help/questions    http://example2.com/questions

但是从 example.com/help/questions/show/some_text 重定向不起作用 - 我有 example2.com/help/questions/show/some_text 而不是 example2.com/questions/show/some_text 使用这样的代码我有一些问题。

RewriteCond %{HTTP_HOST} example.com/help/questions
RewriteRule (.*) http://example2.com/questions/$1 [R=301,L]

我该如何解决? 所有其他页面都正常重定向。

【问题讨论】:

    标签: php .htaccess redirect


    【解决方案1】:

    %{HTTP_HOST} 只匹配主机名而不匹配 URI。

    你可以使用:

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} ^(?:www\.)?example\.com$ [NC]
    RewriteRule ^help/(questions/.*) http://example2.com/$1 [R=301,L,NC,NE]
    

    【讨论】:

    • 我仍然有这样的问题:但是从example.com/help/questions/show/some_text 重定向不起作用-我有example2.com/help/questions/show/some_text 而不是example2.com/questions/show/some_texthelp 不是必须的
    • 确保将此规则作为您的第一条规则,并彻底清除您的浏览器缓存。
    【解决方案2】:
    1. 确保您已在 httpd.conf 或 apache.conf 中设置“AllowOverride All”。
    2. 确保您已启用 rewrite_module、headers_module 和 alias_module apache 模块。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-04
      • 2013-02-24
      • 1970-01-01
      • 2010-10-14
      • 2017-05-18
      • 2016-03-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多