簡體   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