Robots.txt rewrite for many second-level domains

Hello,
how to use “rewrite” and “set” in nginx to use different robots.txt for
different second-level domains.

My idea:
if ($server_name ~* XXX) {
set secondlevel $2
}
rewrite ^/robots.txt$ /robots-$secondlevel.txt last;

Am I on the right way ? Could somebody help me with the regular
expresion XXX ?
Or is there another way ?

On Sun, Jan 06, 2008 at 09:34:28PM +0100, Martin Minka wrote:

expresion XXX ?
Or is there another way ?

First, it better to separate server on server level:

 server {
     ...
 }

 server {
     ...
 }

 server {
     ...
 }

However, if the servers are too common, then you should use:

 server {

     location = /robots.txt {
         if ($http_host ~* "^(one|two|three)\.domain\.com$") {
             set      $secondlevel  $2;
             rewrite  ^   /robots-$secondlevel.txt last;
         }

         root   ...;
     }

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