Trying to do the opposite of www.domain.com -> domain.com

David mishy.cth at gmail.com
Mon Sep 1 03:59:39 MSD 2008


Hi,

Following this example from the docs:

#rewrites http://www.mydomain.nl/foo => http://mydomain.nl/foo
if ($host ~* www\.(.*)) {
  set $host_without_www $1;
  rewrite ^(.*)$ http://$host_without_www$1 permanent; # $1 contains '/foo', not
'www.mydomain.com/foo'
}

Would the opposite of that be:

#rewrites http://mydomain.nl/foo => http://www.mydomain.nl/foo
if ($host ~* !^(.*)\.mydomain\.nl$) {
  rewrite ^(.*)$ http://www.mydomain.nl/$1 permanent;
}

Does that make sense ?

Is $host_without_www a reserved variable ? and is the inverse $host_with_www ?

Thanks






More information about the nginx mailing list