Reputation: 25
I have this old URL from our previous site
http://site.com/fixed-word/changing-category/12345-title-of-story
where the "variables" are
changing-category: example sports, politics etc.
and
12345-title-of-story: 12345 is the old id and the rest is the story slug / title
The new site uses only the story slug in this format
http://site.com/another-fixed-word/title-of-story
Is it possible to create a 301 rewrite rule in nginx to achieve this ?
I tried this:
rewrite ^/fixed-word/([^\?]+)$/([^\?]+)$ /index.php?tipo=old_article&slug=$1 last;
And the idea was to get the slug in php and remove the numeric id from the slug (12345-) but does not work, aging returns 404
Any advice ?
Thanks
Upvotes: 1
Views: 1144
Reputation: 15130
This regular expression is completely wrong:
^/fixed-word/([^\?]+)$/([^\?]+)$
If you just need to create a 301 redirect, then you should use this:
location /fixed-word/ {
rewrite ^/fixed-word/(?:[^/]+)/(?:\d+)-(.+)$ /another-fixed-word/$1 permanent;
}
Upvotes: 0