【问题标题】:NGINX location rewrite for WP permalinkWP 永久链接的 NGINX 位置重写
【发布时间】:2016-08-01 22:15:42
【问题描述】:

所以,我的 WP 具有几乎经典的永久链接结构,例如:/%category%/%year%/%month%/%day%/%postname%/

我想用 301 错误代码重定向到新样式,例如 /%year%/%month%/%day%/%postname%/ 或简单的 /%postname% /

我制定了这条规则,但它们返回相同的 URL。

location ~ "^\/([a-zA-Z0-9_.-]+)\/([0-9]{4})\/([0-9]{2})\/([0-9]{2})\/([a-zA-Z0-9_.-]+)\/$" {
     rewrite ^(.*) $1 permanent;
 }  

或者,对于 /%postname%/,我尝试过这样的代码:

location ~ "^\/([a-zA-Z0-9_.-]+)\/([0-9]{4})\/([0-9]{2})\/([0-9]{2})\/([a-zA-Z0-9_.-]+)\/$" {
     rewrite ^(.*) $5 permanent;
 }

但此代码返回空响应。

请帮我解决问题。如果我错了,我无法理解。谢谢!

【问题讨论】:

    标签: wordpress nginx url-rewriting nginx-location


    【解决方案1】:

    所以,很简单:

    location ~ "^/([a-zA-Z0-9_.-]+)/([0-9]{4})/([0-9]{2})/([0-9]{2})/([a-zA-Z0-9_.-]+)/$" {
         rewrite ^(.*)/(.*)/(.*)/(.*)/(.*)/ /$5/ permanent;
     }  
    

    此规则将 WP 中的 /category/year/month/day/postname/ 重写为 /postname/ URL,并带有搜索引擎的 301 错误代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多