1
我想只有当它是由谷歌访问用下面的代码来限制访问sitemap.xml
:只允许Google查看sitemap.xml?
reverse_dns = Resolv.getname(request.remote_ip)
throw_404 unless reverse_dns.include?("goog") || reverse_dns.include?("localhost")
但如果是IP地址的主机名失败。例如:
Resolv::ResolvError: no name for 64.233.191.255
这是一个谷歌机器人IP地址。
关于如何完成这个任务或者Stackoverflow如何做到这一点(Stackexchange将它的sitemap.xml限制为Google)。