Reputation: 1340
I have a dozen links from an old website I need to redirect to a new path. This is the old URL buildup:
/news/item/{id}-{name}
Which needs to be redirected to:
/blog/item/{id}-{name}
Now I hear you thinking, just swap the news with the blog in your redirect. Well that could be if it was that simple, but as you can imagine, the old News category contained also the news items, and because it's an old website they never split these items into different category's. So I need to identify when I can redirect it to the blog page. Luckily every blog post contains a static string, which we can use to identify the url (I think).
So you have the following URLS:
/news/item/{id}-{name}
/blog/item/{id}-{name}
The static word that is in the {name} of the url is blogpost-name , but can I use that to identify the URLS to redirect to the /blog/ page?
2 Examples:
/news/item/33018-It-was-a-great-day-to--ride
/news/item/29110-Blogpost-author-john-doe-time-to-come-apart
Here we got 2 items in the news url, but only 1 of them, the actual blogpost can only be switched. The other URL needs to stay intact and working.
Upvotes: 0
Views: 36
Reputation: 74078
To redirect all blog posts from /news/...
to /blog/...
, except those being "news", you must identify them by "-Blogpost-", capture the part you want to keep (...)
and reuse this in the target URL $1
RewriteRule ^news/(item/\d+-Blogpost-.+)$ /blog/$1 [R,L]
When everything works as it should, you may replace R
with R=301
(permanent redirect). Never test with R=301
.
Upvotes: 1