how to rewrite or redirect a subdomain?
Igor Sysoev
is at rambler-co.ru
Wed Aug 8 19:38:55 MSD 2007
On Wed, Aug 08, 2007 at 11:25:36PM +0800, Steve Chu wrote:
> That's really awesome, Thanks.
>
> We have thousands of xxx subdomains, here's our configure:
>
> server {
> server_name _ *.yyy.example.com;
>
> if ($http_host ~ "^(.+?)\.yyy\.example\.com") {
> set $host $1;
> }
>
> rewrite ^ http://yyy.example.com/$host;
> }
>
> The "^(.+?)\." calls a dead loop, because it meet xxx.yyy.example.com,
> and redirect xxx.yyy.example.com to yyy.example.com/xxx, then redirect
> yyy.example.com/xxx to
> yyy.example.com/yyy, then to yyy.example.com/yyy... it seems a mistake.
Request to yyy.example.com should never go to this server - it should be
handled by first server:
server {
server_name yyy.example.com;
...
}
> Does server_name "*.yyy.example.com" match "yyy.example.com"?
No, ".yyy.example.com" matches "yyy.example.com".
> On 8/8/07, Igor Sysoev <is at rambler-co.ru> wrote:
> > On Wed, Aug 08, 2007 at 10:16:44PM +0800, Steve Chu wrote:
> >
> > > I digged the nginx rewrite module, found that it is hard to
> > > rewrite/redirect a subdomain, here's my situation:
> > > I wanna rewrite/redirect "http://xxx.yyy.example.com" to
> > > "http://yyy.example.com/xxx".
> > > I found there's a Variables $host, but how to split it to get "xxx",
> > > then use rewrite module?
> > > any idea?
> >
> > server {
> > server_name yyy.example.com;
> > ...
> > }
> >
> > server {
> > server_name xxx.yyy.example.com *.www.example.com;
> >
> > if ($http_host ~ "^(.+?)\.") {
> > set $host $1;
> > }
> >
> > rewrite ^ http://yyy.example.com/$host;
> > }
> >
> >
> > --
> > Igor Sysoev
> > http://sysoev.ru/en/
> >
> >
>
>
> --
> Steve Chu
> http://stvchu.org
>
--
Igor Sysoev
http://sysoev.ru/en/
More information about the nginx
mailing list