【问题标题】:Drupal 301 redirectsDrupal 301 重定向
【发布时间】:2014-04-10 20:28:45
【问题描述】:

我正在 Drupal 中进行一组 301 重定向。

我在 .htaccess 文件中使用标准方法:

<IfModule mod_rewrite.c>
RewriteEngine on

Redirect 301 /user/testimonials http://thesitedomain.com/testimonials
Redirect 301 /user/contact http://thesitedomain.com/contact
</IfModule>

但返回 URL 以“?q=user”结尾并停止工作。例如:

http://thesitedomain.com/about?q=user/about

我不擅长 htaccess 重定向(显然),而且我根本不是 Drupal 专家。

另外,如果您知道全面的 htaccess 重写资源,我将非常感谢您阅读 hat。

【问题讨论】:

    标签: .htaccess redirect drupal http-status-code-301


    【解决方案1】:

    您需要使用mod_rewrite 来去除现有的查询字符串:

    RewriteEngine On
    
    RewriteRule ^user/testimonials/?$ http://thesitedomain.com/testimonials? [L,NC,R=301] 
    RewriteRule ^user/contact/?$ http://thesitedomain.com/contact? [L,NC,R=301] 
    

    注意目标中的尾随 ? 会去除现有的查询字符串。

    【讨论】:

    • 不幸的是不起作用......它只是进入同一页面:/user/testimonials/
    • 确保此 301 规则是您根 .htaccess 中的第一个规则,然后您在新浏览器中进行测试。
    【解决方案2】:

    我无法与drupal交谈,但我知道您不需要将这些重定向包含在&lt;IfModule mod_rewrite.c&gt;标签中,因为它们不使用RewriteEngine,以下就足够了:

    Redirect 301 /user/testimonials http://thesitedomain.com/testimonials
    Redirect 301 /user/contact http://thesitedomain.com/contact
    

    【讨论】:

      【解决方案3】:

      两个网址都在同一个drupal中吗?或者你是从不同的网站搬来的? 我的意思是:

      也许您需要为 /user/testimonials 添加一个 URL 别名,例如 /testimonials

      请参阅 drupal 7 中 /admin/config/search/path 的 admin 下。

      【讨论】:

        【解决方案4】:

        使用 .htaccess 文件不是一个好习惯,因为在某些更新中您还必须更新 .htaccess 文件。

        您可以尝试GlobalRedirect 模块来管理您的重定向。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2012-01-25
          • 2010-12-07
          • 2010-09-26
          • 2013-01-07
          • 2018-03-06
          • 2012-02-06
          • 2010-11-05
          • 2011-11-17
          相关资源
          最近更新 更多