PHP cURL - 如何检查 Google Crawler 是否获取正确的 robots.txt

问题描述 投票:0回答:2

Google 以某种方式开始索引我网站的 https 版本。为了阻止这个问题,我阅读了一个教程,其中说我需要 2 个不同的 robots.txt 文件和 .htaccess 中的一些附加代码

.htaccess

RewriteCond %{HTTPS} on
RewriteRule ^robots\.txt$ robots-https.txt

机器人-https.txt

User-agent: *
Disallow: /

几天过去了,谷歌仍然没有开始对 https 页面进行取消索引。 所以现在我有点担心,想测试一下更改是否正确完成。

有没有办法使用 PHP 和 cURL 来检查 https 连接中正在使用哪个 robots.txt?

感谢您的任何建议!

php curl
2个回答
0
投票

如果您从不同的文档根目录提供网站的两个版本,则只需保留 robots.txt 的两个副本即可:

/home/sites/example.com/http/robots.txt
/home/sites/example.com/https/robots.txt

如果它们都来自同一物理目录,那么您可以简单地在虚拟主机定义中使用 Apache 别名:

<virtualhost example.com:443>
   Alias /robots.txt  /physical/path/to/ssl/robots.txt
</virtualhost>

<virtualhost example.com:80>
   Alias /robots.txt /path/to/standard/robots.txt
</virtualhost>

无需诉诸正则表达式和 mod_rewrite。


0
投票

用户代理*:

此行表示以下指令适用于所有搜索引擎爬虫(用户代理)。 不允许:

该指令指定了爬虫不允许访问的内容。在这种情况下,您发布的内容没有特定的禁止规则,这意味着默认情况下所有爬虫都可以访问所有内容。

但是如果你想阻止某些页面被爬虫访问,你可以为这些路径添加禁止指令。例如,对于“/login/”目录,您可以添加以下行: 禁止:/登录/

© www.soinside.com 2019 - 2024. All rights reserved.