|
|
|
|
|
你是否遇到有網站不斷引用你的網站內容(例如圖片)?這會嚴重占用你的帶寬,增加你的服務器負荷,所以需要禁止此類行為。
使用.htaccess禁止某網站抓取你的內容
如果有某個網站要抓取你的網站內容,那么阻止此類網站訪問你的內容,只需在你的網站配置文件.htaccess中使用下面的代碼。
RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http://.*somebadwebsite\.com [NC]
RewriteRule .* - [F]
此代碼將禁止域名為“ somebadwebsite.com”的來路訪問你的網站,觸發(fā)規(guī)則便返回403(禁止訪問)的提示。
如果你有多個阻止對象,請使用以下代碼。
RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http://.*somebadwebsite\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://.*example\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://.*lastexample\.com [NC]
RewriteRule .* - [F]
上面代碼的幾個域名替換為你要阻止的域名。
如果你僅要阻止一個網站,例如:如果你只需要阻止“ somebadwebsite.com”,則該代碼看起來類似于先前的代碼。
如果你有五個要阻止的網站,則代碼如下所示。
RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http://.*somebadwebsite\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://.*example\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://.*example2\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://.*example3\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://.*lastexample\.com [NC]
RewriteRule .* - [F]
如上例所示,最后一個不應包含“ [OR]”。