Rewrite regexp for subdomains

Hi i need to blabla.example.org or dummy.example.org anotherdummy send
me to www.example.org (another words *.example.org must redirect to
www.example.org) but when i type www.example.org it can’t send to
www.example.org cause it’s loop. Help me to realize this construction.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,146043,146043#msg-146043

On 30 Out 2010 19h08 WEST, [email protected] wrote:

Hi i need to blabla.example.org or dummy.example.org anotherdummy
send me to www.example.org (another words *.example.org must
redirect to www.example.org) but when i type www.example.org it
can’t send to www.example.org cause it’s loop. Help me to realize
this construction.

Create two server blocks. Put the www server name before the * and it
should work:

See http://nginx.org/en/docs/http/server_names.html

Exact names precede patterns or regex server names.

— appa

On 31 Out 2010 03h48 WET, [email protected] wrote:

It doesn’t work. With server_name www.example.org and server_name
*.example.org my site doesn’t redirect blabla.example.org to
www.example.org

server {
listen [::]:80; # ipv6

   server_name www.example.com;
   (...)

}

server {
## This is to avoid the spurious if for sub-domain name
## rewriting. See http://wiki.nginx.org/Pitfalls#Server_Name.
listen [::]:80; # ipv6
server_name *.example.com;
rewrite ^ $scheme://www.example.com$request_uri permanent;
} # server domain rewrite.

I haven’t tried it myself. Try it.

— appa

It doesn’t work. With server_name www.example.org and server_name
*.example.org my site doesn’t redirect blabla.example.org to
www.example.org

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,146043,146134#msg-146134

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs