Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress 拒绝直接访问sitemap.xml(仅允许搜索机器人程序)_Wordpress_.htaccess_Bots_Sitemap_Apache2.4 - Fatal编程技术网

Wordpress 拒绝直接访问sitemap.xml(仅允许搜索机器人程序)

Wordpress 拒绝直接访问sitemap.xml(仅允许搜索机器人程序),wordpress,.htaccess,bots,sitemap,apache2.4,Wordpress,.htaccess,Bots,Sitemap,Apache2.4,我使用的是Apache 2.4,需要限制用户对sitemap_index.xml的直接访问,只允许已知的机器人访问站点地图,您能帮我使用一些.htaccess规则吗?您可以添加一个规则,根据使用的用户代理阻止对站点地图的访问,当然,这不是很安全,因为用户始终可以将用户代理设置为其他内容,但这可能适用于您的特定情况: RewriteEngine On # Check so we have a user-agent equal to 'googlebot' RewriteCond %{HTTP_US

我使用的是Apache 2.4,需要限制用户对sitemap_index.xml的直接访问,只允许已知的机器人访问站点地图,您能帮我使用一些.htaccess规则吗?

您可以添加一个规则,根据使用的用户代理阻止对站点地图的访问,当然,这不是很安全,因为用户始终可以将用户代理设置为其他内容,但这可能适用于您的特定情况:

RewriteEngine On
# Check so we have a user-agent equal to 'googlebot'
RewriteCond %{HTTP_USER_AGENT} !googlebot$ [NC]
# If the user-agent is not correct we return a 403: Forbidden
RewriteRule ^sitemap\.xml - [F,L]
您可以简单地更改上述条件,以包括您希望包括的任何用户代理,例如:

RewriteCond %{HTTP_USER_AGENT} !^(googlebot|spider|foo)$ [NC]
上述方法允许用户代理设置为googlebot、spider或foo的请求访问sitemap.xml文件