Apache 模組 mod rewrite RewriteCond 通過檢查HTTP REFERER避免
阿新 • • 發佈:2018-11-08
分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow
也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!
Apache - 模組 - mod_rewrite - RewriteCond - 通過檢查HTTP_REFERER避免靜態圖片盜鏈對效能有嚴重影響
在避免靜態圖片盜鏈時,可以用RewriteCond檢查referer,如果不是來自於特定的網站或搜尋引擎,則轉向另一個頁面。在使用這些 RewriteCond和不使用之間作比較,每條RewriteCond將降低速度1%以上,隨著這個列表的增長,對於速度的影響將進一步突出。因此使用 大量RewriteCond來保護靜態內容的方案,雖然能減和網路流量,但是也會消耗伺服器效能。在具體使用過程中一定要平衡各方面條件。
[例1]
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$ [NC]
RewriteCond %{HTTP_REFERER} !suixie.com[NC]
RewriteCond %{HTTP_REFERER} !zhuaxia.com [NC]
RewriteCond %{HTTP_REFERER} !baidu.com [NC]
RewriteCond %{HTTP_REFERER} !bloglines.com [NC]
RewriteCond %{HTTP_REFERER} !google.com [NC]
RewriteRule .* new.html [L]
RewriteRule .* old.html [L]
[例2]
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://newsight.net/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://nsncity.net/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^[url=http://]http://[/url](www.)?newsight.net/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^[url=http://]http://[/url](www1.)?newsight.net/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^[url=http://]http://[/url](www.)?nsncity.net/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^[url=http://]http://[/url](gallery.)?newsight.net/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^[url=http://]http://[/url](club.)?newsight.net/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^[url=http://]http://[/url](club.)?nsncity.net/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^[url=http://]http://[/url](exec.)?newsight.net/.*$ [NC]
RewriteRule .(gif|GIF|jpg|JPG|png|PNG|swf|SWF|pdf|PDF|js|JS|css|CSS)$ http://www.newsight.net/images/logo.gif [R,L]
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} ^BlackWidow [OR]
RewriteCond %{HTTP_USER_AGENT} ^Bot/ mailto:[email protected] [OR]
RewriteCond %{HTTP_USER_AGENT} ^ChinaClaw [OR]
RewriteCond %{HTTP_USER_AGENT} ^Custo [OR]
RewriteCond %{HTTP_USER_AGENT} ^DISCo [OR]
RewriteCond %{HTTP_USER_AGENT} ^Download/ Demon [OR]
RewriteCond %{HTTP_USER_AGENT} ^eCatch [OR]
RewriteCond %{HTTP_USER_AGENT} ^EirGrabber [OR]
RewriteCond %{HTTP_USER_AGENT} ^EmailSiphon [OR]
RewriteCond %{HTTP_USER_AGENT} ^EmailWolf [OR]
RewriteCond %{HTTP_USER_AGENT} ^Express/ WebPictures [OR]
RewriteCond %{HTTP_USER_AGENT} ^ExtractorPro [OR]
RewriteCond %{HTTP_USER_AGENT} ^EyeNetIE [OR]
RewriteCond %{HTTP_USER_AGENT} ^FlashGet [OR]
RewriteCond %{HTTP_USER_AGENT} ^GetRight [OR]
RewriteCond %{HTTP_USER_AGENT} ^GetWeb! [OR]
RewriteCond %{HTTP_USER_AGENT} ^Go!Zilla [OR]
RewriteCond %{HTTP_USER_AGENT} ^Go-Ahead-Got-It [OR]
RewriteCond %{HTTP_USER_AGENT} ^GrabNet [OR]
RewriteCond %{HTTP_USER_AGENT} ^Grafula [OR]
RewriteCond %{HTTP_USER_AGENT} ^HMView [OR]
RewriteCond %{HTTP_USER_AGENT} HTTrack [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Image/ Stripper [OR]
RewriteCond %{HTTP_USER_AGENT} ^Image/ Sucker [OR]
RewriteCond %{HTTP_USER_AGENT} Indy/ Library [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^InterGET [OR]
RewriteCond %{HTTP_USER_AGENT} ^Internet/ Ninja [OR]
RewriteCond %{HTTP_USER_AGENT} ^JetCar [OR]
RewriteCond %{HTTP_USER_AGENT} ^JOC/ Web/ Spider [OR]
RewriteCond %{HTTP_USER_AGENT} ^larbin [OR]
RewriteCond %{HTTP_USER_AGENT} ^LeechFTP [OR]
RewriteCond %{HTTP_USER_AGENT} ^Mass/ Downloader [OR]
RewriteCond %{HTTP_USER_AGENT} ^MIDown/ tool [OR]
RewriteCond %{HTTP_USER_AGENT} ^Mister/ PiX [OR]
RewriteCond %{HTTP_USER_AGENT} ^Navroad [OR]
RewriteCond %{HTTP_USER_AGENT} ^NearSite [OR]
RewriteCond %{HTTP_USER_AGENT} ^NetAnts [OR]
RewriteCond %{HTTP_USER_AGENT} ^NetSpider [OR]
RewriteCond %{HTTP_USER_AGENT} ^Net/ Vampire [OR]
RewriteCond %{HTTP_USER_AGENT} ^NetZIP [OR]
RewriteCond %{HTTP_USER_AGENT} ^Octopus [OR]
RewriteCond %{HTTP_USER_AGENT} ^Offline/ Explorer [OR]
RewriteCond %{HTTP_USER_AGENT} ^Offline/ Navigator [OR]
RewriteCond %{HTTP_USER_AGENT} ^PageGrabber [OR]
RewriteCond %{HTTP_USER_AGENT} ^Papa/ Foto [OR]
RewriteCond %{HTTP_USER_AGENT} ^pavuk [OR]
RewriteCond %{HTTP_USER_AGENT} ^pcBrowser [OR]
RewriteCond %{HTTP_USER_AGENT} ^RealDownload [OR]
RewriteCond %{HTTP_USER_AGENT} ^ReGet [OR]
RewriteCond %{HTTP_USER_AGENT} ^SiteSnagger [OR]
RewriteCond %{HTTP_USER_AGENT} ^SmartDownload [OR]
RewriteCond %{HTTP_USER_AGENT} ^SuperBot [OR]
RewriteCond %{HTTP_USER_AGENT} ^SuperHTTP [OR]
RewriteCond %{HTTP_USER_AGENT} ^Surfbot [OR]
RewriteCond %{HTTP_USER_AGENT} ^tAkeOut [OR]
RewriteCond %{HTTP_USER_AGENT} ^Teleport/ Pro [OR]
RewriteCond %{HTTP_USER_AGENT} ^VoidEYE [OR]
RewriteCond %{HTTP_USER_AGENT} ^Web/ Image/ Collector [OR]
RewriteCond %{HTTP_USER_AGENT} ^Web/ Sucker [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebAuto [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebCopier [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebFetch [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebGo/ IS [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebLeacher [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebReaper [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebSauger [OR]
RewriteCond %{HTTP_USER_AGENT} ^Website/ eXtractor [OR]
RewriteCond %{HTTP_USER_AGENT} ^Website/ Quester [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebStripper [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebWhacker [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebZIP [OR]
RewriteCond %{HTTP_USER_AGENT} ^Wget [OR]
RewriteCond %{HTTP_USER_AGENT} ^Widow [OR]
RewriteCond %{HTTP_USER_AGENT} ^WWWOFFLE [OR]
RewriteCond %{HTTP_USER_AGENT} ^Xaldon/ WebSpider [OR]
RewriteCond %{HTTP_USER_AGENT} ^Zeus
RewriteRule ^.* - [F,L]
[Apache - 關鍵詞]
apache[Apache - 常用模組]
mod_aliasmod_rewrite
[mod_rewrite模組 - 關鍵詞]
httxt2dbmmod_rewrite
ornext
RewriteBase
RewriteCond
RewriteEngine
RewriteLog
RewriteLogLevel
RewriteMap
RewriteRule
[mod_rewrite模組 - 常見用途]
改變查詢引數的設定位置[mod_rewrite模組 - 標記]
RewriteLog, 設定重寫引擎日誌的檔名
[mod_rewrite模組 - RewriteCond重寫條件]
通過檢查HTTP_REFERER避免靜態圖片盜鏈對效能有嚴重影響
[mod_rewrite模組 - RewriteRule重寫規則]
匹配任意字串時,可以藉助正則表示式的靈活特性
[mod_rewrite模組 - 常見問題]
RewriteRule中的正則表示式需要考慮是否要加上^(匹配字串開頭)RewriteRule中的正則表示式需要考慮是否要對.轉義(匹配任意字元還是僅匹配.字元)
RewriteRule中的R標記用於傳送重定向
與PHP整合時不需要對$_GET額外處理