Sub-domain in variable

Hi guys,

I have question. My server_name looks like this:

server_name ~^(www.)(?[^.]).(?[^.])$;

but I need, for my website do subdomains. I try:

server_name
~^(www.)?(?.)(?[^.]).(?[^.])$;

but won’t work for me. And what will be super, if subdomain emtpy se to
default (mean string “default”).

Can me anybody help?

Posted at Nginx Forum:

Check your subdomain regex. Right now, if will only work if your
subdomain is a dot :wink:

It should be (?[^.]*) or (?[^.]+)

_Nik

Thanks lot, but still wont to work.
And how i set $subdomain to “default” if subdomain doesnt exists?

I try this:
~^(www.)(?[^.])(?[^.]).(?[^.]*)$

Posted at Nginx Forum:

Ok, I love u :D! Work perfectly… I solved all thx :slight_smile:

Posted at Nginx Forum:

The “www” part is probably causing a problem too. As the regex is
written it will only match “www...” 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
(one.two.domain.com).

_Nik

What is the working form of this? I want to redirect all ..* to .
(e.g.
sub.domain.tld to domain.tld) because I have different domains and
tdls.
Any help appreciated.

Posted at Nginx Forum: