wildcard to rewritre multi domains to www

Marcus Clyne maccaday at gmail.com
Mon Sep 7 14:44:33 MSD 2009

>> I think if you look at your regex again, you'll see that it's not that 
>> it doesn't match any domains with sub domains, it matches any domains 
>> with a dot somewhere in the middle.  The \. guarantees that there's a 
>> dot, but the other characters can be anything.
> Ah, so instead of .+ it'd need to be [^.]+ as in:
> server_name ~(^[^.]+\.[^.]+$);
That would be fine - for domains with just the top level domain before 
the main name, e.g. test.com.  However, if you also deal with URLs with 
a country code as well, e.g. test.co.uk, it's not going to capture them 
because they'll look like the subdomains you were trying to avoid 
capturing.  You could create a rather complex RE using all the country 
codes and tld's to fully capture only the main domain, and no 
sub-domains, but it'd be pretty long and would probably waste 
considerable processing time.  Personally, I like to keep things simple. :-)



More information about the nginx mailing list