Join the community today
Register Now

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:
    3:43 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
    • Like Like x 1
  2. eva2000

    eva2000 Administrator Staff Member

    30,883
    6,907
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,400
    Local Time:
    10:43 AM
    Nginx 1.13.x
    MariaDB 5.5
  3. AlekseY

    AlekseY Member

    47
    4
    8
    Feb 18, 2015
    Ratings:
    +7
    Local Time:
    3:43 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
    • Like Like x 1
  4. eva2000

    eva2000 Administrator Staff Member

    30,883
    6,907
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,400
    Local Time:
    10:43 AM
    Nginx 1.13.x
    MariaDB 5.5
    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

    30,883
    6,907
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,400
    Local Time:
    10:43 AM
    Nginx 1.13.x
    MariaDB 5.5
  6. AlekseY

    AlekseY Member

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

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

    AlekseY Member

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

    eva2000 Administrator Staff Member

    30,883
    6,907
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,400
    Local Time:
    10:43 AM
    Nginx 1.13.x
    MariaDB 5.5
    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/
     
    • Like Like x 1
  9. AlekseY

    AlekseY Member

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