gpt4 book ai didi

apache - 使用 htaccess 的域特定机器人文件将 robots.txt 重写为 example.com.txt 或回退到 default.txt

转载 作者:行者123 更新时间:2023-12-02 13:08:27 29 4
gpt4 key购买 nike

我想要特定于域的 robots.txt,到目前为止这有效:

RewriteRule ^robots\.txt$ robots/%{HTTP_HOST}.txt [L]

但我希望有一个后备方案,因此如果domain.txt 文件不存在,则转到default.txt

这并没有真正起作用,因为它会重定向所有不存在的文件名,而且我已经在不同的规则中有一个 !-f :RewriteCond %{REQUEST_FILENAME} !-fRewriteRule robots/default.txt [L]

所以我需要:1-catch robots.txt 请求2-发送到 robots/domain.txt(如果存在)3-否则发送到 robots/default.txt

最佳答案

尝试:

RewriteCond %{DOCUMENT_ROOT}/robots/%{HTTP_HOST}.txt -f
RewriteRule ^robots\.txt$ robots/%{HTTP_HOST}.txt [L]

RewriteRule ^robots\.txt$ robots/domain.txt [L]

第一条规则中的条件检查目标 robots 文件是否存在,如果存在,robots.txt 将被重写。因此,只有当第一条规则不适用时,第二条规则才会应用。

关于apache - 使用 htaccess 的域特定机器人文件将 robots.txt 重写为 example.com.txt 或回退到 default.txt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23418849/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com