robots.txt rewrite for many second-level domains
Igor Sysoev
is at rambler-co.ru
Sun Jan 6 23:48:29 MSK 2008
On Sun, Jan 06, 2008 at 09:34:28PM +0100, Martin Minka wrote:
> 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 ?
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 ...;
}
--
Igor Sysoev
http://sysoev.ru/en/
More information about the nginx
mailing list