perusio / drupal-with-nginx

Running Drupal using nginx: an idiosyncratically crafted bleeding edge configuration.
855 stars 246 forks source link

redirect only https and www rewrite #143

Closed pedrosanchezpernia closed 10 years ago

pedrosanchezpernia commented 10 years ago

I'm switching to https and I am trying to have 3 cases to redirect to https://stage.example.com. My conf is based on the standard example.com.conf, and so far this is the problem.
ok: https://stage.example.com http://stage.example.com >> https://stage.example.com bad: http://www.stage.example.com >> show the default "t works" page https://www.stage.example.com >> page not available

I am using return 301 https://stage.example.com$request_uri; at the end of "server listen 80"

Thanks for any tips.

iryston commented 10 years ago

Hi! You should add this section at the top of site configuration. server { server_name www.stage.example.com; return 301 $scheme://stage.example.com$request_uri; } # server domain rewrite.

perusio commented 10 years ago

You can add the www.stage.example.com to the redirect. Since you're on a HTTPS only host you can simplify the HTTP server config like this.

server {
    server_name www.stage.example.com stage.example.com;

    return 301 https://stage.example.com;
}