wildcard to rewritre multi domains to www
Cliff Wells
cliff at develix.com
Sun Sep 6 22:05:40 MSD 2009
On Sat, 2009-09-05 at 23:53 +0300, Marcus Clyne wrote:
> Hi,
>
> Cliff Wells wrote:
> > Try this:
> >
> > server {
> > server_name ~(^.+\..+$);
> > set $name $1;
> > rewrite ^ http://www.$name$request_uri? permanent;
> > }
> >
> >
> That will cause problems if the domain begins with www. If you want to
> capture both www.domain.tld and domain.tld and rewrite to include the
> www., you could use
That's odd, as I tested it and it worked fine ;-) It specifically does
not match domains starting with any subdomain, it leaves that to another
server section. Here's the complete test I used:
server {
server_name ~^(.+\..+)$;
set $name $1;
rewrite ^ http://www.$name$request_uri? permanent;
}
server {
server_name www.test1.com;
root /var/www;
autoindex on;
}
I tested with both http://test1.com and http://www.test1.com and got the
expected results.
Regards,
Cliff
--
http://www.google.com/search?q=vonage+sucks
More information about the nginx
mailing list