Nginx URL rewrite help needed in removing folder in specific scenario

Discussion in 'Programming' started by Impaler, Oct 31, 2019.

  1. Impaler

    Impaler Aspirant

    15
    1
    +0
    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]
     
  2. we_are_borg

    we_are_borg Administrator

    5,348
    1,417
    +2,120
    Try:

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

    Impaler Aspirant

    15
    1
    +0
    this online generator apache to nginx result does not work. tried it. it makes /forums/ go 404
     
  4. Impaler

    Impaler Aspirant

    15
    1
    +0
    anyone?
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.