Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need not to serve robots.txt for any subdomain. For example, domain.com/robots.txt should be available, but blabla.domain.com/robots.txt should return 404.

I've tried it like so, but it didn't work:

set $subdomain FALSE;
if ($host ~* "^(([a-z0-9_\-]+)\.domain\.com)$") {
    set $subdomain TRUE;
}

location ~ "robots.txt$"{
    if ($subdomain = TRUE){
        return 404;
    }
}
share|improve this question
up vote 1 down vote accepted
location ~ /robots.txt
     {
       if ($host != 'domain.com') {
       return 404;
     }
}
share|improve this answer
    
This works, but why did someone downvote this answer? – Rakhim Davletkaliyev Jul 30 '13 at 15:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.