繁体   English   中英

用于WP永久链接的NGINX位置重写

[英]NGINX location rewrite for WP permalink

因此,我的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;
 }

但是此代码返回空响应。

请帮我解决问题。 我错了,我听不懂。 谢谢!

因此,这非常简单:

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM