Nginx 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 NGINX 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.

In apache this one did the trick, but in nginx that obviously doesn't work
Code:
RewriteRule ^forums/(blogs|gallery|files)/(.*)$ /$1/$2 [L,R=301]
 

we_are_borg

Administrator
Joined
Jan 25, 2011
Messages
5,718
Try:

Code:
# nginx configuration 
 location /forums {   
rewrite ^/forums/(blogs|gallery|files)/(.*)$ /$1/$2 redirect; 
}
 

Impaler

Aspirant
Joined
Aug 29, 2019
Messages
27
this online generator apache to nginx result does not work. tried it. it makes /forums/ go 404
 
Top