How robots.txt file should be properly written for subdomains?

China☆狼群 提交于 2019-12-25 05:21:54

问题


Can someone explain me how should i write a robots.txt file if i want that all crawlers index root and some specific subdomains

User-agent: *
Allow: /
Allow: /subdomain1/
Allow: /subdomain2/

Is this right? And where should i put it? In the root (public_html) folder or in each subdomain folder?


回答1:


There is no way to specify rules for different subdomains within a single robots.txt file. A given robots.txt file will only control crawling of the subdomain it was requested from. If you want to block some subdomains and allow others, then you need to serve different robots.txt files from the different subdomains.

For example, if you want to allow crawling of http://crawlme.example.com/, but you want to block crawling of http://nocrawl.example.com/ then:

http://crawlme.example.com/robots.txt should contain:

# Allow everything:
User-agent: *
Disallow:

and http://nocrawl.example.com/robots.txt should contain:

# Block everything:
User-agent: *
Disallow: /


来源:https://stackoverflow.com/questions/43320228/how-robots-txt-file-should-be-properly-written-for-subdomains

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!