how to rewrite or redirect a subdomain?

Igor Sysoev is at rambler-co.ru
Wed Aug 8 19:57:07 MSD 2007


On Wed, Aug 08, 2007 at 10:51:24PM +0700, Denis F. Latypoff wrote:

> Hello Steve,
> 
> Wednesday, August 8, 2007, 10:25:36 PM, you wrote:
> 
> > That's really awesome, Thanks.
> 
> > We have thousands of xxx subdomains, here's our configure:
> 
> > server {
> -         server_name  _  *.yyy.example.com;
> +         server_name  xxx.yyy.example.com *.yyy.example.com;
> 
>           # yyy.sample.com matches "_"

No, "_" does not match anythig.

> >         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.
> 
> > Does server_name  "*.yyy.example.com" match "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/
> >>
> >>
> 
> 
> 
> 
> 
> -- 
> Best regards,
>  Denis                            mailto:denis at gostats.ru
> 
> 

-- 
Igor Sysoev
http://sysoev.ru/en/





More information about the nginx mailing list