I have the following two domains:



Both point to same folder which is public_html. What I want is a different robots.txt file for each domain. So when someone browse example.com/robots.txt then a different file is shown. And when someone go to test.example.com/robots.txt then a different file is shown.

How can I do this using URL rewriting in .htaccess?


Remeber that no one from Internet can see your directory tree, so stackoverflow.com/ and test.stackoverflow.com are completely diffrent sites for us and search robots.

You can do that by checking the HTTP host in query:

RewriteCond %{HTTP_HOST} ^test
RewriteRule robots.txt someotherrobots.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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