Welcome to Centmin Mod Community
Become a Member

Redirect from http to https and non-www to www

Discussion in 'Introductions' started by AlekseY, Feb 18, 2015.

  1. AlekseY

    AlekseY Member

    47
    4
    8
    Feb 18, 2015
    Ratings:
    +7
    Local Time:
    5:19 AM
    # save file and restart Nginx to enable


    |=> context http <=|
    Code:
    map $scheme:$host $redirect  {
    ~^(https?):www.domain.com    "1";
         http:domain.com  "1";
         default    "0";             
    }
    
    |=> context server ssl <=|
    Code:
    listen 80;
    if ($redirect) {
        return 301 https://$server_name$request_uri;
    }
    
    Hello from Russia!
     
    Last edited: Feb 18, 2015
  2. eva2000

    eva2000 Administrator Staff Member

    53,461
    12,128
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,668
    Local Time:
    12:19 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
  3. AlekseY

    AlekseY Member

    47
    4
    8
    Feb 18, 2015
    Ratings:
    +7
    Local Time:
    5:19 AM
    [QUOTE = "EVA2000, после: 10911, член: 1"] Добро пожаловать [USER = 395]AlekseY [/ USER] :)

    Интересный подход, хотя нет более простые способы ни к WWW | Centmin Mod сообщество [/QUOTE]

    problem from https:wvww.domen.com to https.domain.com!
    NO redirect.
    my post up - works. :)
     
    Last edited: Feb 18, 2015
  4. eva2000

    eva2000 Administrator Staff Member

    53,461
    12,128
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,668
    Local Time:
    12:19 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    oh yes that.. for that I use something like

    for nowww to www

    Code:
    ## redirect www to nowww
          if ($host = 'www.sslspdy.com' ) {
             return 301 https://$server_name$request_uri;
          }
    btw, using CODE tags for code is easier to format so might want to edit first post's code in CODE tags ;)
     
  5. eva2000

    eva2000 Administrator Staff Member

    53,461
    12,128
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,668
    Local Time:
    12:19 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
  6. AlekseY

    AlekseY Member

    47
    4
    8
    Feb 18, 2015
    Ratings:
    +7
    Local Time:
    5:19 AM
    Yes, I saw that decision. =)

    MAP is far more elegant !
    And do not make another server to 80 (http)
     
  7. AlekseY

    AlekseY Member

    47
    4
    8
    Feb 18, 2015
    Ratings:
    +7
    Local Time:
    5:19 AM
    [​IMG]
    307 redirect...
     
  8. eva2000

    eva2000 Administrator Staff Member

    53,461
    12,128
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,668
    Local Time:
    12:19 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Yeah that's normal it's what chromium browsers see AFAIK 307.. to others it's 301

    307 internal redirect being probably chrome's cached 301 (permanent) redirect ?

    Code:
    curl -I http://community.centminmod.com/threads/redirect-from-http-to-https-and-non-www-to-www.2319/
    HTTP/1.1 301 Moved Permanently
    Server: nginx centminmod
    Date: Tue, 17 Feb 2015 22:04:02 GMT
    Content-Type: text/html
    Content-Length: 178
    Connection: keep-alive
    Location: https://community.centminmod.com/threads/redirect-from-http-to-https-and-non-www-to-www.2319/
     
  9. AlekseY

    AlekseY Member

    47
    4
    8
    Feb 18, 2015
    Ratings:
    +7
    Local Time:
    5:19 AM
    Error Chrome?
    or so conceived?
    307 - temporarily moved .... ==> 302
    Cache disable =>> print screen
     
    Last edited: Feb 18, 2015