【问题标题】:htaccess 301 regular expressionhtaccess 301 正则表达式
【发布时间】:2016-04-25 00:55:35
【问题描述】:

我刚刚将博客平台从定制平台转移到 WordPress 中,看起来有几个永久链接结构需要 301 重定向。这是如何在正则表达式中使用正则表达式完成的?

旧:www.domain.com/blog/tag/tag-name.html
新:www.domain.com/blog/tag/tag-name/

旧:www.domain.com/blog/2016/01/01/post-name-here.html
新:www.domain.com/blog/2016/01/01/post-name-here/

虽然我可以在现有的 .htaccess 文件中执行此操作,但我认为这是不切实际的,因为我有一堆现有的博客文章和类别/标签。

Redirect /blog/2016/01/01/post-name-here.html http://www.domain.com/blog/2016/01/01/post-name-here/

【问题讨论】:

    标签: .htaccess mod-rewrite


    【解决方案1】:

    您可以使用 RedirectMatch :

    RedirectMatch 301 ^/blog/(tag/)?(.+)\.html$ http://www.example.com/$1$2
    

    这将重定向:

    【讨论】:

    • 我认为这里需要额外的斜杠; OP似乎已经具体说明了它。 :)
    猜你喜欢
    • 2013-07-19
    • 2018-05-31
    • 2012-06-21
    • 2017-06-21
    • 2014-12-05
    • 1970-01-01
    • 2019-04-17
    • 2015-01-30
    相关资源
    最近更新 更多