【发布时间】:2018-03-12 15:11:29
【问题描述】:
我想用这个示例脚本阻止一些域:
.htaccess 文件
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http?://([^.]+\.)*google\.com [NC]
RewriteRule .* - [F]
</IfModule>
index.php 文件
<?php
// set location
$address = "Brooklyn+NY+USA";
//set map api url
$url = "http://maps.google.com/maps/api/geocode/json?address=$address";
//call api
$json = file_get_contents($url);
$json = json_decode($json);
$lat = $json->results[0]->geometry->location->lat;
$lng = $json->results[0]->geometry->location->lng;
echo "Latitude: " . $lat . ", Longitude: " . $lng;
?>
结果:纬度:40.6781784,经度:-73.9441579
问:如何使用 .htaccess 阻止来自该域http://maps.google.com/maps/api/geocode/json?address= 的数据?
我的意思是如果域被阻止,结果必须为空。但我仍然无法解决它..
【问题讨论】:
-
要获得合理的答案,您可能应该提供更多关于您要达到的目标的详细信息。例如,您正在谈论“阻止某些域”或“阻止来自该域的数据”,但在您的示例
.htaccess中,您有一个基于 REFERER 的RewriteCond。我不确定这是否是您想要的。 -
.htaccess 被 Web 服务器用于确定它如何处理请求。它不会在你的情况下发挥作用。如果您想阻止应用程序发出传出 Web 请求,则必须以其他方式执行此操作,可能更改 /etc/hosts 文件以使 maps.google.com 无法正确解析,或者只是从php 文件。