【问题标题】:Silverstripe and 301 RedirectMatchSilverstripe 和 301 重定向匹配
【发布时间】:2014-10-17 12:00:30
【问题描述】:

我已经建立了一个需要重定向旧网址的网站。旧站点使用数据对象作为页面概念,因此可以在 example.com/news/view/my-post 找到博客条目。新站点使用博客模块,因此现在可以在 example.com/news/my-post 中找到博客条目。我尝试将以下重定向添加到我的 htaccess:

RedirectMatch permanent ^/news/view/(.+) http://www.example.com/news/$1

当我导航到旧帖子时,例如,使用上述 RedirectMatch 的 example.com/news/view/my-post,我得到以下网址:mysite.com/news/my-post?url= /news/view/my-post 并从 Silverstripe 获得 404

另一个奇怪的行为是,当我附加除 ?url=* 之外的任何内容时(例如 ?everything=everything,我没有得到 404 页面)。

Silverstripe 是否将 ?url=/news/view/my-post 附加到 url?如何添加 RedirectMatch 而不会收到 Silverstripe 的 404?

【问题讨论】:

    标签: silverstripe


    【解决方案1】:

    我相信 apache 的 mod_alias(提供 RedirectMatch 指令)与 mod_rewrite 冲突。请改用 mod_rewrite - 并注意在默认的 SilverStripe 通常放置在其 .htaccess 文件之前插入您的规则。

    规则如下所示:

    RewriteEngine On
    RewriteRule ^news/view/(.*)$ /news/$1 [R=301,NC,L]
    
    ... SilverStripe Rules come after this.
    

    RewriteEngine On 确保将处理这些重写规则。可以多次在您的 virtualhost/.htaccess 中使用它 - 但请记住,只有在第一次出现之后出现的规则才会被处理。我通常将它放在我的虚拟主机定义中。

    [R=301] 表示永久 301 重定向。如果是临时的,请使用 [R=302]。

    [NC] 用于忽略大小写,使正则表达式匹配不区分大小写。

    [L]会立即返回这条规则,并停止后续规则的处理。

    http://httpd.apache.org/docs/current/mod/mod_rewrite.html供参考

    【讨论】:

      猜你喜欢
      • 2016-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-15
      • 2013-06-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多