【发布时间】:2017-01-09 19:29:34
【问题描述】:
我需要在 url post (wordpress) 上写一个删除 id 的规则
https://myqite.com/12-title-of-post-one
https://myqite.com/45-title-of-post-two
https://myqite.com/56-title-of-post-nn
到
https://myqite.com/title-of-post-one
https://myqite.com/title-of-post-two
https://myqite.com/title-of-post-nn
尝试了几个选项,但都失败了。
rewrite ^([0-9]+)-(.+)$ $2 permanent;
其他
rewrite ^([0-9]+)-(.+)$ $2 last;
【问题讨论】:
-
正则表达式
([0-9]+)匹配所有数字。将rewrite ^([0-9]+)-(.+)$ $2 last;替换为rewrite ^(.+)$ $2 last;会得到什么? -
正则表达式完美运行。 ([0-9]+- 匹配 url 的数量,例如 59-。这个元素不喜欢。它是第一个 var o 正则表达式。(.*) 它是 var 的第二部分。这是一个类似的 url。在帖子上,它的解释非常干净我喜欢什么。谢谢。rubular.com/r/pp4pjDZAac
-
nginxURI 以/开头。您可能应该使用类似:rewrite ^/[0-9]+-(.+)$ /$1 -
rewrite ^/[0-9]+-(.+)$ /$1 last;不起作用。这条线在其他之后工作正常。rewrite ^/sitemap_index.xml$ /index.php?sitemap=1 last;rewrite ^/([^/]+?)-sitemap([0-9]+)?.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;谢谢
标签: wordpress nginx url-rewriting