URL rewrite help needed in removing folder in specific scenario

Impaler

Aspirant
Joined
Aug 29, 2019
Messages
27
Hello, after I have upgraded my site I see that once I go live with new version some parts of the website URLs will not be redirected for gallery, blogs and files because of new structure. And there is no way fixing it within the CMS there just isn't so my goal is to use htaccess redirects.

I wonder do any of you know any .htaccess rewrite tricks to make such redirects possible?

http://www.website.com/forums/blogs/* -> http://www.website.com/blogs/*
http://www.website.com/forums/gallery/* -> http://www.website.com/gallery/*
http://www.website.com/forums/files/* -> http://www.website.com/files/*

I actually need the part forums dropped from the URL only and ONLY when the address is going for forums+blogs/gallery/files. Don't want to loose that google traffic.

So for example
http://www.website.com/forums/blogs/entry123/my-dog/ is redirected to
http://www.website.com/blogs/entry123/my-dog/

BUT
http://www.website.com/forums/topic/my-dog/
is left alone and working just like before because the following subfolder is neither blogs or gallery or files.

So far I came up only with such a rule but it removes forums part from every URL which is not the goal. I can't think of a way to add en exclusion to make it work only if it is followed by these 3 words.

Code:
RewriteRule ^forums/(.*)$ /$1 [L,NC,R]

I'd be very thankful for your help.
 

Impaler

Aspirant
Joined
Aug 29, 2019
Messages
27
The answer is

Code:
RewriteRule ^forums/(blogs|gallery|files)/(.*)$ /$1/$2 [L,R=301]
 
Top