当前位置: > Linux服务器 > apache >

apache中实施防盗链一例

时间:2014-10-18 19:08来源:linux.it.net.cn 作者:it

apache中实施防盗链一例,供大家学习参考。

示例:
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$ [NC]
RewriteCond %{HTTP_REFERER} !mydomain.org [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ no.png [L,NC]
#RewriteRule \.(gif|jpg|js|css)$ - [F]

 若 HTTP_REFERER 非空 (来源为其他站点,非直接连接) 并且

若 HTTP_REFERER 非(www.)mydomain.com开头(忽略大小写[NC]) (来源非本站)

对于所有含有 .gif/.jpg/.js/.css 结尾的文件给出 403 Forbidden 错误[F]

也可指定响应,如下例显示替换图片

RewriteRule \.(gif|jpg)$ [R,L]

[R] - 转向(Redirect)

[L] - 连接(Link)

RewriteCond %{HTTP_REFERER} !www.feedburner.com [NC]
#RewriteRule \.(gif|jpg|jpeg|png|bmp|rar|zip|exe|dll|js|css)$ - [F]
RewriteRule \.(jpg|jpeg|gif|png|bmp|rar|zip|exe|dll|js|css)$ 403.html [L,NC]

bo-blog Rewrite for Apache:
 

复制代码代码如下:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /

#New rules since 2.1.0 beta 2
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [L]

RewriteRule ^post/([0-9]+)/?([0-9]+)?/?([0-9]+)?/?$ read.php?entryid=$1&page=$2?=$3 [QSA,L]
RewriteRule ^page/([0-9]+)/([0-9]+)/?$ index.php?mode=$1&page=$2 [QSA,L]
RewriteRule ^starred/([0-9]+)/?([0-9]+)?/?$ star.php?mode=$1&page=$2 [QSA,L]
RewriteRule ^category/([^/]+)/?([0-9]+)?/?([0-9]+)?/?$ index.php?go=category_$1&mode=$2&page=$3 [QSA,L]
RewriteRule ^archiver/([0-9]+)/([0-9]+)/?([0-9]+)?/?([0-9]+)?/?$ index.php?go=archive&cm=$1&cy=$2&mode=$3&page=$4 [QSA,L]
RewriteRule ^date/([0-9]+)/([0-9]+)/([0-9]+)/?([0-9]+)?/?([0-9]+)?/?$ index.php?go=showday_$1-$2-$3&mode=$4&page=$5 [QSA,L]
RewriteRule ^user/([0-9]+)/?$ view.php?go=user_$1 [L]
RewriteRule ^tags/([^/]+)/?([0-9]+)?/?([0-9]+)?/?$ tag.php?tag=$1&mode=$2&page=$3 [QSA,L]
RewriteRule ^component/id/([0-9]+)/?$ page.php?pageid=$1 [L]
RewriteRule ^component/([^/]+)/?$ page.php?pagealias=$1 [L]

#Force redirection for old rules
RewriteRule ^post/([0-9]+)\.htm$ post/$1/ [R=301,L]
RewriteRule ^post/([0-9]+)\_([0-9]+)\.htm$ post/$1/$2/ [R=301,L]
RewriteRule ^post/([0-9]+)\_([0-9]+)\_([0-9]+)\.htm$ post/$1/$2/$3/ [R=301,L]
RewriteRule ^index\_([0-9]+)\_([0-9]+)\.htm$ page/$1/$2/ [R=301,L]
RewriteRule ^star\_([0-9]+)\_([0-9]+)\.htm$ starred/$1/$2/ [R=301,L]
RewriteRule ^category\_([0-9]+)\.htm$ category/$1/ [R=301,L]
RewriteRule ^category\_([0-9]+)\_([0-9]+)\_([0-9]+)\.htm$ category/$1/$2/$3/ [R=301,L]
RewriteRule ^archive\_([0-9]+)\_([0-9]+)\.htm$ archiver/$1/$2/ [R=301,L]
RewriteRule ^archive\_([0-9]+)\_([0-9]+)\_([0-9]+)\_([0-9]+)\.htm$ archiver/$1/$2/$3/$4/ [R=301,L]
RewriteRule ^showday\_([0-9]+)\_([0-9]+)\_([0-9]+)\.htm$ date/$1/$2/$3/ [R=301,L]
RewriteRule ^showday\_([0-9]+)\_([0-9]+)\_([0-9]+)\_([0-9]+)\_([0-9]+)\.htm$ date/$1/$2/$3/$4/$5/ [R=301,L]

#Customized URL
RewriteRule ^([^\/]*)\.html$ $1/ [R=301,L]
RewriteRule ^([^/|.]*)/?([0-9]+)?/?([0-9]+)?/?$ read.php?blogalias=$1&page=$2?=$3 [QSA,L]
</IfModule>


(责任编辑:IT)
------分隔线----------------------------