block domain from .htaccess



我想通过此示例脚本阻止某些域:

.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

问:如何阻止此域中的数据http://maps.google.com/maps/api/geocode/json?address= use .htaccess?

我的意思是,如果域被阻塞,结果必须为空白。但是我仍然无法解决。

您可以这样尝试。

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_REFERER} ^https?://([^.]+.)*google.com [NC]
    RewriteRule .* - [F]
</IfModule>

,或者如果要拒绝从任何特定域中访问访问,请执行此

SetEnvIfNoCase Referer "domain.com" bad_referer
Order Allow,Deny
Allow from ALL
Deny from env=bad_referer

如果有人尝试访问www.domain.com,这将显示拒绝访问。如果用户单击domain.com上的链接,则将其重定向到您的网站,然后会看到错误403 Forbidden


RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http://www.google.com/
RewriteRule /* http://www.anydomain.com [R,L]

使用此功能您可以将任何用户从www.google.com重定向到anydomain.com


更新

RewriteEngine on
RewriteCond %{HTTP_REFERER} maps.google.com [NC]
RewriteRule .* - [F]

RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http://(www.)?maps.google.com [NC]
RewriteRule (.*)    - [F]

最新更新