我知道可以为Apache服务器*上的所有域创build一个robots.txt文件 ,但是我想追加到每个域(如果预先存在的话)robots.txt。 我希望所有域名都有一些通用的规则,但是我需要允许不同的域名拥有自己独特的规则。
有没有办法做到这一点?
(*在我的情况下Apache 2.2.x)
从Apache的angular度来看, robots.txt只是一个服务的资产。 您可以通过传递输出filter来改变请求robots.txt时返回的内容。
如果你想附加一些文字,你可以定义一个外部filter 。 假设Apache在类Unix操作系统上运行,filterconfiguration可能是
ExtFilterDefine appendRobotstxt cmd="/bin/cat - /var/www/html/robots-tail.txt" <Location /robots.txt> SetOutputFilter appendRobotstxt </Location>
这将连接robots-tail.txt到响应的结尾。
请注意,您可能需要合并这些更改。 如果一个域已经有了
User-agent: * Disallow: /search
而你想为所有域添加
User-agent: * Disallow: /admin/
你必须做到这一点
User-agent: * Disallow: /search Disallow: /admin/
因为robots.txtparsing器只要find与其匹配的块就会停止。