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

mike mike503 at gmail.com
Mon Sep 1 10:52:07 MSD 2008


yeah, i took your suggestion and this is what i've been using, with
the added addition of redirecting and keeping the URI

        server {
                listen 80;
                server_name www.michaelshadle.com;
                rewrite ^/(.*) http://michaelshadle.com/$1 permanent;
        }

        server {
                listen 80;
                server_name michaelshadle.com;
                index index.php;
                root /htdocs/michaelshadle.com/;
                ... etc ...
        }


On 8/31/08, Igor Sysoev <is at rambler-co.ru> wrote:
> On Sun, Aug 31, 2008 at 11:59:39PM +0000, David wrote:
>
> > 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 ?
>
> No, $host_without_www is not reserved name.
> Try the following:
>
> - if ($host ~* !^(.*)\.mydomain\.nl$) {
> + if ($host !~* ^(.*)\.mydomain\.nl$) {
>
> BTW, it's better to use something like this instead of "if":
>
> server {
>     server_name  www.maydomain.nl;
>     ...
> }
>
> server {
>     server_name  maydomain.nl;
>     rewrite ^(.*)$ http://www.mydomain.nl/$1 permanent;
> }
>
>
> --
> Igor Sysoev
> http://sysoev.ru/en/
>
>





More information about the nginx mailing list