简体   繁体   English

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

[英]NGINX location rewrite for WP permalink

So, I have WP with almost classic permalink structure, like: /%category%/%year%/%month%/%day%/%postname%/ 因此,我的WP具有几乎经典的永久链接结构,例如: /%category%/%year%/%month%/%day%/%postname%/

I would like to redirect with 301 error code to new style, like /%year%/%month%/%day%/%postname%/ or simple /%postname%/ . 我想将301错误代码重定向到新样式,例如/%year%/%month%/%day%/%postname%/或简单的/%postname%/

I've made this rule, but they return same URL. 我已经制定了此规则,但是它们返回相同的URL。

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

Or, for /%postname%/ I've tried code like this: 或者,对于/%postname%/,我尝试过这样的代码:

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

But this code return empty response. 但是此代码返回空响应。

Please, help me solve the issue. 请帮我解决问题。 I can't catch were I'm wrong. 我错了,我听不懂。 Thanks! 谢谢!

So, it was very simple: 因此,这非常简单:

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

This rule rewrite /category/year/month/day/postname/ to /postname/ URL in WP with 301 error code for search engines. 此规则使用搜索引擎的301错误代码将/ category / year / month / day / postname /重写为WP中的/ postname / URL。

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

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