Help/How to? Redirect all request to https://www using Nginx+Spdy

Code:
if ($ssl_protocol = "") {
    rewrite ^/(.*) https://$http_host/$1 permanent;
}
I mean how to redirect all request to www.
Redirecting to https already works fine with this code:
Code:
server {
    server_name .domain.com;
    return 301 https://www.domain.com$request_uri;
}

server {
  listen 443 ssl spdy;
  server_name www.domain.com;

The only thing that didn't work is this:
From https://domain.com to https://www.domain.com =
 
Oops... misread what was/wasn't working...

Code:
if ($http_host = "digitalpoint.com") {
    rewrite ^       https://www.digitalpoint.com/?  permanent;
}
 
  • Like
Reactions: rdn
Here's my current config:
PHP:
server {
    server_name domain.com www.domain.com;
    return 301 https://www.domain.com$request_uri;
}

server {
    listen 443 ssl spdy;
    server_name www.domain.com;

domain.com to https://www.domain.com = Works
www.domain.com to https://www.domain.com = Works
https://domain.com to https://www.domain.com = Not working
What you have works, if it does not then look at the logs as there is something else breaking your redirection. Example: https://axivo.com
You can further cleanup that config:
Code:
server {
    server_name domain.com *.domain.com;
    return 301 https://www.domain.com$request_uri;
}
server {
    listen server_ip:443 ssl spdy default_server;
    server_name www.domain.com;
    ...
}

Oops... misread what was/wasn't working...

Code:
if ($http_host = "digitalpoint.com") {
    rewrite ^       https://www.digitalpoint.com/?  permanent;
}
That is bad... and deprecated. He has the proper solution above.
 
Last edited:
Back
Top Bottom