Sub-domain in variable

Nikolas Stevenson-Molnar nik.molnar at
Tue Mar 26 18:19:05 UTC 2013

The "www" part is probably causing a problem too. As the regex is
written it will only match "www.<subdomain>.<domain>.<tdl>" which I'm
guessing isn't what you intent. I would instead treat "www" as another
possible subdomain.


Note I haven't tested this, but it's similar to a pattern I've used. The
$subdomain variable will be either the subdomain, "www", or will be
empty. It would need some more tweaking to handle multiple subdomains


On 3/26/2013 11:01 AM, huttarichard wrote:
> Thanks lot, but still wont to work.
> And how i set $subdomain to "default" if subdomain doesnt exists?
> I try this:
> ~^(www\.)(?<subdomain>[^\.]*)(?<domain>[^\.]*)\.(?<tld>[^\.]*)$
> Posted at Nginx Forum:,237799,237814#msg-237814
> _______________________________________________
> nginx mailing list
> nginx at

More information about the nginx mailing list