1

I have a website which was running on custom CSM. However, as it grew larger we had to move it to wordpress.

On the old CMS we had url structure to articles similar to this:

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

We would like to redirect all requests to old articles to this structure

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

Here category is wordpress slug for category

I did try some redirect rules in nginx, however, it turns out I am not good with regex expressions. I am clueless. Please help me do it. I don't know where to turn to.

It would be highly appreciated.

Update: Edited original link structure to iron out confusions about "category" being a static slug. It is not. There are multiple categories and sub categories:

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

2 Answers 2

0

Assuming that "category" is literal and "something" is a placeholder, something like this might work for you:

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

If only old CMS URIs begin with /category, you could place the rewrite inside a location block to improve efficiency:

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

See this link for help with regular expressions.

1
  • Category is not literal in Old CMS, however, it is in wordpress. Sorry for the confusion. I have edited the OP to refine my question. There are multiple categories and subcategories on the old CMS. which needs to be removed in the redirect from the article link. See OP. And Thank you very much for helping me out. Jun 14, 2017 at 6:50
0

Use the following RewriteRules. It must be work as per your requirement.

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

RewriteRule ^/parent-category/([^\/]+)/([0-9]+)-([^\/]+)$ /parent-category/$1/$3 [R=301,L,NE]

https://example.com/parent-category/546-title-of-the-post

RewriteRule ^/parent-category/([0-9]+)-([^\/]+)$ /parent-category/$2 [R=301,L,NE]

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .