【问题标题】:Convert these rewrite apache rules to nginx将这些重写 apache 规则转换为 nginx
【发布时间】:2013-01-23 12:00:58
【问题描述】:

在我的 Wordpress 中,我更改了帖子的永久链接结构。为了不让旧链接出现 404 错误,我想将旧的永久链接重定向到新的永久链接。 According to this,必须在我的 .htacess 中添加以下代码,以便我可以从旧帖子链接重定向到新帖子链接:

RedirectMatch 301 ^/([0-9]{4})/([0-9]{2})/([^/]+).html$ http://myurl.com/$3

这很好,但是,我不使用 Apache——我使用 nginx。如何将此规则转换为 nginx?我已经尝试了一个 apache 到 nginx 的在线转换器,但没有成功。

谢谢!

【问题讨论】:

    标签: wordpress apache .htaccess nginx


    【解决方案1】:

    我相信这就是你想要的。根据this 页面,“永久”为 301。

    rewrite "^/([0-9]{4})/([0-9]{2})/([^/]+).html$" http://myurl.com/$3 permanent;
    

    【讨论】:

    • 根据wiki.nginx.org/HttpRewriteModule 中给出的注释。 Note: for curly braces( { and } ), as they are used both in regexes and for block control, to avoid conflicts, regexes with curly braces are to be enclosed with double quotes (or single quotes). 所以重写规则将是rewrite "^/([0-9]{4})/([0-9]{2})/([^/]+).html$" http://myurl.com/$3 permanent;
    猜你喜欢
    • 1970-01-01
    • 2016-06-18
    • 1970-01-01
    • 1970-01-01
    • 2014-06-30
    • 2016-08-09
    • 1970-01-01
    • 2018-05-06
    相关资源
    最近更新 更多