A robots.txt file with a specific domain with htaccess overwrites the robots.txt file in example.com.txt or returns to default.txt

I want to have a domain-specific robots.txt file, and still it works:

RewriteRule ^robots\.txt$ robots/%{HTTP_HOST}.txt [L]

But I would like to have a backup, so if the domain.txt file does not exist, go to default.txt

And this does not work, as it redirects all non-existent file names, plus I already have it! -f in another rule: RewriteCond% {REQUEST_FILENAME}! -f RewriteRule robots / default.txt [L]

So I need: Requests 1-catch robots.txt 2-Send robots /domain.txt if it exists 3-Else send robots / default.txt

+4
source share
1 answer

Try:

RewriteCond %{DOCUMENT_ROOT}/robots/%{HTTP_HOST}.txt -f
RewriteRule ^robots\.txt$ robots/%{HTTP_HOST}.txt [L]

RewriteRule ^robots\.txt$ robots/domain.txt [L]

, , , robots.txt . , , .

+3

Source: https://habr.com/ru/post/1538935/


All Articles