Which is better?

Is one better than the other?

combining www. and non-www, and using a conditional:

server {
listen 80;
server_name michaelshadle.com www.michaelshadle.com;
… index, root, all that stuff…

if ($http_host ~ "^www.(.*)") {
    set $name $1;
    rewrite ^/(.*) http://$name/$1 permanent;
}

}

or making two physical server blocks?

server {
listen 80;
server_name michaelshadle.com;
… index, root, all that stuff…

}

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

I use two server blocks and everywhere I looked for examples they use
that. So i guess it is safe to use two server blocks as in your first
example it will check the regex every time you have a request, which
is slower than no regex at all :slight_smile:

Kiril

We have an SEO directive to only publish on one url, but also support
a HUGE set of typo domains, we use this stanza

server {
listen 80 default;

 rewrite ^(.+)$ http://www.redbubble.com$1 permanent;

}

server {
listen 80;
server_name www.redbubble.com;

 ...

}

On Mon, Apr 21, 2008 at 05:50:25PM -0700, mike wrote:

    set $name $1;

}

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

Second, of course.