Join the community today
Register Now

Nginx Question about redirects

Discussion in 'Install & Upgrades or Pre-Install Questions' started by Jay Chen, Dec 25, 2017.

  1. Jay Chen

    Jay Chen Member

    65
    15
    8
    Sep 10, 2017
    Ratings:
    +26
    Local Time:
    9:33 PM
    I am merging 2 websites into 1, a.com and b.com.
    I want to set up the redirect for a.com and b.com to go to a.com and all http to go to https.
    I also have to mass redirect all the url. Is the code below the best way to implement this?
    Thank you.
    Code:
    map $request_uri $new_uri {
       default "";
       /old/a.com-url /new/b.com-url;
       /old/b.com-url /new/b.com-url;
       ...
    }
     server {
       server_name a.com www.a.com b.com www.b.com;
       return 301 https://a.com$request_uri;
       include /usr/local/nginx/conf/staticfiles.conf;
     }
    
    server {
      listen 443 ssl http2;
      server_name a.com www.a.com;
       if ($new_uri != "") {
           rewrite ^(.*)$ $new_uri permanent;
       }
    }

     
    Last edited: Dec 25, 2017
..