Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serve different robots.txt based on HTTP_HOST

I have two sites both being indexed by google using the same codebase:

dev.mysite.com and example.com

I want to serve a different robots.txt based on each domain.

Currently I have:

RewriteBase /

RewriteCond %{HTTP_HOST} ^dev\.mysite\.com$ [NC]
RewriteRule ^robots\.txt$ robots\.txt\.dev [L]

However this doesn't seem to work. Can someone point me in the right direction.

like image 656
digital Avatar asked Jan 27 '26 11:01

digital


1 Answers

For me worked following by adding extra condition

RewriteCond %{HTTP_HOST} ^dev\.mysite\.com
RewriteCond %{REQUEST_URI} (robots\.txt)
RewriteRule .* robots-dev.txt [L]
like image 72
Elvin Risti Avatar answered Jan 30 '26 13:01

Elvin Risti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!