使用nginx重写从url中删除ID或号码

我有一个运行在自定义CSM上的网站。 然而,随着它越来越大,我们不得不把它移到wordpress。

在旧CMS上,我们使用了与以下类似的文章的url结构:

https://example.com/parent-category/child-category/7564-title-of-the-article https://example.com/parent-category https://example.com/parent-category/child-category 

我们希望将所有请求redirect到这个结构的旧文章

 https://example.com/title-of-the-article https://example.com/category/parent-category https://example.com/category/parent-category/child-category 

这里的分类是wordpress slug

我在nginx中尝试了一些redirect规则,然而事实certificate我对于正则expression式并不擅长。 我无言以对 请帮我做。 我不知道该去哪里。

这将不胜感激。

更新:编辑原始的链接结构,以消除有关“类别”是一个静态的slu conf混乱。 不是这样。 有多个类别和子类别:

 https://example.com/review/app/734-title-of-the-post https://example.com/news/546-title-of-the-post https://example.com/blog/opinion/456-title-of-the-post 

假设“类别”是字面的,“东西”是一个占位符,像这样的东西可能适合你:

 rewrite ^/category/[^/]+/\d+-(.+)$ /$1 permanent; 

如果只有旧的CMS URI以/category开头,则可以将重写放在一个位置块中以提高效率:

 location ^~ /category/ { rewrite ^/category/[^/]+/\d+-(.+)$ /$1 permanent; } 

请参阅此链接获取正则expression式的帮助。