.htaccess 重写多机器人的规则.txt

.htaccess 重写多机器人的规则.txt,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,我有一个有多个域的网站,我需要为每个域一个robots.txt 例如: example.com will have robots-com.txt example.se will have robots-org.txt example.co.uk will have robots-co.uk.txt 等等。。。 URL应该是example.com/robots.txt 所以我写了这个: RewriteRule ^.*example\.(.*)/robots\.txt robots-$1.txt

我有一个有多个域的网站,我需要为每个域一个robots.txt

例如:

example.com will have robots-com.txt
example.se will have robots-org.txt
example.co.uk will have robots-co.uk.txt
等等。。。 URL应该是example.com/robots.txt

所以我写了这个:

RewriteRule ^.*example\.(.*)/robots\.txt robots-$1.txt [L]
(我认为)它将获取域并将其添加到robots文件的末尾。 但它不起作用

我该怎么办,可能吗


我这样重写了它,仍然不起作用:

RewriteCond %{HTTP-HOST} ^.*example\.(.*)$
RewriteRule ^robots\.txt$ robots-%1\.txt [L]

工作解决方案:

RewriteCond %{HTTP_HOST} ^.*example\.(.*)$
RewriteRule ^robots\.txt$ /robots-%1\.txt [L]

您想查看一下
RewriteCond%{HTTP-HOST}
并在您的重写规则中使用%1反向引用。@JonLin我试过了,但没有成功。请参见上面的.in.htaccess文件,URI中的前导斜杠被删除,因此匹配项应该是
^robots\.txt$
@JonLin我删除了它,但它仍然不起作用…抱歉,变量是%{HTTP\u HOST}(下划线,不是破折号)