-2

May I ask Where and How to redirect

http://domain.com, http://www, https://domain.com

to

https://www

?

talamaki
  • 5,324
  • 1
  • 27
  • 40
  • Possible duplicate of [NGINX Redirect http to https and non-www to ww](http://stackoverflow.com/questions/21106998/nginx-redirect-http-to-https-and-non-www-to-ww) – talamaki May 25 '16 at 10:15

1 Answers1

0

Where

In your Nginx config file (the main or vhost depending on your setup)

How

Try rewrite:

    server {
    listen      80;
    server_name www.domain.com domain.com;
    rewrite     ^ https://www.doamin.com$request_uri? permanent;
}

or return:

server {
    listen      80;
    server_name www.domain.com domain.com;
    return 301 https://www.domain.com$request_uri
}

Choice is your when it comes to Return vs Rewrite:

REWRITE

  • Only the part of the original url that matches the regex is rewritten.
  • Slower than a Return.
  • Returns HTTP 302 (Moved Temporarily) in all cases, irrespective of permanent.
  • Suitable for temporary url changes.

RETURN

  • The entire url is rewritten to the url specified.
  • Faster response than rewrite.
  • Returns HTTP 301 (Moved Permanently).
  • Suitable for permanent changes to the url.
  • No need to set permanent.

Officila Nginx Docs on return/rewrite.

MMT
  • 1,931
  • 3
  • 19
  • 35