简体   繁体   中英

Rewrite nginx rule for delete ID on url

I need write a rule for delete id on url post (wordpress)

https://myqite.com/12-title-of-post-one
https://myqite.com/45-title-of-post-two
https://myqite.com/56-title-of-post-nn

to

https://myqite.com/title-of-post-one
https://myqite.com/title-of-post-two
https://myqite.com/title-of-post-nn

Try several options but fail.

rewrite ^([0-9]+)-(.+)$ $2 permanent;

Other

rewrite ^([0-9]+)-(.+)$ $2 last;

After several test I get solution

location ~ /([0-9]+)-(.+) {
   return 301 https://$server_name/$2;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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