From: Rich Bowen
The following technique forbids the practice of other sites + including your images inline in their pages. This practice is + often referred to as "hotlinking", and results in + your bandwidth being used to serve content for someone else's + site.
+This technique relies on the value of the
+ HTTP_REFERER variable, which is optional. As
+ such, it's possible for some people to circumvent this
+ limitation. However, most users will experience the failed
+ request, which should, over time, result in the image being
+ removed from that other site.
There are several ways that you can handle this + situation.
+ +In this first example, we simply deny the request, if it didn't
+ initiate from a page on our site. For the purpose of this example,
+ we assume that our site is www.example.com.
+RewriteCond %{HTTP_REFERER} !^$
+RewriteCond %{HTTP_REFERER} !www.example.com [NC]
+RewriteRule \.(gif|jpg|png)$ - [F,NC]
+In this second example, instead of failing the request, we display + an alternate image instead.
+ +
+RewriteCond %{HTTP_REFERER} !^$
+RewriteCond %{HTTP_REFERER} !www.example.com [NC]
+RewriteRule \.(gif|jpg|png)$ /images/go-away.png [R,NC]
+In the third example, we redirect the request to an image on some + third-party site.
+ +
+RewriteCond %{HTTP_REFERER} !^$
+RewriteCond %{HTTP_REFERER} !www.example.com [NC]
+RewriteRule \.(gif|jpg|png)$ http://other.site.com/image.gif [R,NC]
+Of these techniques, the last two tend to be the most effective + in getting people to stop hotlinking your images, because they will + simply not see the image that they expected to see.
+ +If all you wish to do is deny access to the resource, rather + than redirecting that request elsewhere, this can be + accomplished without the use of mod_rewrite:
+ +
+ SetEnvIf Referer example\.com localreferer
+ <FilesMatch \.(jpg|png|gif)$>
+ Order deny,allow
+ Deny from all
+ Allow from env=localreferer
+ </FilesMatch>
+
@@ -94,7 +177,8 @@ RewriteRule ^/secret/files/ - [F]
<Location /secret/files>
Order allow,deny
Allow from all
- Deny from env=goaway
+ Deny from env=goaway
+ </Location>
As noted above, this technique is trivial to circumvent, by simply diff --git a/docs/manual/rewrite/access.xml b/docs/manual/rewrite/access.xml index c45c51e05d2..170d7e751bd 100644 --- a/docs/manual/rewrite/access.xml +++ b/docs/manual/rewrite/access.xml @@ -43,6 +43,87 @@ configuration.
The following technique forbids the practice of other sites + including your images inline in their pages. This practice is + often referred to as "hotlinking", and results in + your bandwidth being used to serve content for someone else's + site.
+This technique relies on the value of the
+ HTTP_REFERER variable, which is optional. As
+ such, it's possible for some people to circumvent this
+ limitation. However, most users will experience the failed
+ request, which should, over time, result in the image being
+ removed from that other site.
There are several ways that you can handle this + situation.
+ +In this first example, we simply deny the request, if it didn't
+ initiate from a page on our site. For the purpose of this example,
+ we assume that our site is www.example.com.
+RewriteCond %{HTTP_REFERER} !^$
+RewriteCond %{HTTP_REFERER} !www.example.com [NC]
+RewriteRule \.(gif|jpg|png)$ - [F,NC]
+In this second example, instead of failing the request, we display + an alternate image instead.
+ +
+RewriteCond %{HTTP_REFERER} !^$
+RewriteCond %{HTTP_REFERER} !www.example.com [NC]
+RewriteRule \.(gif|jpg|png)$ /images/go-away.png [R,NC]
+In the third example, we redirect the request to an image on some + third-party site.
+ +
+RewriteCond %{HTTP_REFERER} !^$
+RewriteCond %{HTTP_REFERER} !www.example.com [NC]
+RewriteRule \.(gif|jpg|png)$ http://other.site.com/image.gif [R,NC]
+Of these techniques, the last two tend to be the most effective + in getting people to stop hotlinking your images, because they will + simply not see the image that they expected to see.
+ +If all you wish to do is deny access to the resource, rather + than redirecting that request elsewhere, this can be + accomplished without the use of mod_rewrite:
+ +
@@ -99,7 +180,8 @@ RewriteRule ^/secret/files/ - [F]
<Location /secret/files>
Order allow,deny
Allow from all
- Deny from env=goaway
+ Deny from env=goaway
+ </Location>
As noted above, this technique is trivial to circumvent, by simply diff --git a/docs/manual/rewrite/rewrite_guide.html.en b/docs/manual/rewrite/rewrite_guide.html.en index f50aa5c085d..4ad260dc408 100644 --- a/docs/manual/rewrite/rewrite_guide.html.en +++ b/docs/manual/rewrite/rewrite_guide.html.en @@ -56,7 +56,6 @@
From Old to New (intern)
From Old to New (extern)
From Static to Dynamic
Forbidding Image "Hotlinking"
Proxy Deny
External Rewriting Engine
Web Cluster with Consistent URL SpaceThe following technique forbids the practice of other sites - including your images inline in their pages. This practice is - often referred to as "hotlinking", and results in - your bandwidth being used to serve content for someone else's - site.
-This technique relies on the value of the
- HTTP_REFERER variable, which is optional. As
- such, it's possible for some people to circumvent this
- limitation. However, most users will experience the failed
- request, which should, over time, result in the image being
- removed from that other site.
There are several ways that you can handle this - situation.
- -In this first example, we simply deny the request, if it didn't
- initiate from a page on our site. For the purpose of this example,
- we assume that our site is www.example.com.
-RewriteCond %{HTTP_REFERER} !^$
-RewriteCond %{HTTP_REFERER} !www.example.com [NC]
-RewriteRule \.(gif|jpg|png)$ - [F,NC]
-In this second example, instead of failing the request, we display - an alternate image instead.
- -
-RewriteCond %{HTTP_REFERER} !^$
-RewriteCond %{HTTP_REFERER} !www.example.com [NC]
-RewriteRule \.(gif|jpg|png)$ /images/go-away.png [R,NC]
-In the third example, we redirect the request to an image on some - third-party site.
- -
-RewriteCond %{HTTP_REFERER} !^$
-RewriteCond %{HTTP_REFERER} !www.example.com [NC]
-RewriteRule \.(gif|jpg|png)$ http://other.site.com/image.gif [R,NC]
-Of these techniques, the last two tend to be the most effective - in getting people to stop hotlinking your images, because they will - simply not see the image that they expected to see.
- -The following technique forbids the practice of other sites - including your images inline in their pages. This practice is - often referred to as "hotlinking", and results in - your bandwidth being used to serve content for someone else's - site.
-This technique relies on the value of the
- HTTP_REFERER variable, which is optional. As
- such, it's possible for some people to circumvent this
- limitation. However, most users will experience the failed
- request, which should, over time, result in the image being
- removed from that other site.
There are several ways that you can handle this - situation.
- -In this first example, we simply deny the request, if it didn't
- initiate from a page on our site. For the purpose of this example,
- we assume that our site is www.example.com.
-RewriteCond %{HTTP_REFERER} !^$
-RewriteCond %{HTTP_REFERER} !www.example.com [NC]
-RewriteRule \.(gif|jpg|png)$ - [F,NC]
-In this second example, instead of failing the request, we display - an alternate image instead.
- -
-RewriteCond %{HTTP_REFERER} !^$
-RewriteCond %{HTTP_REFERER} !www.example.com [NC]
-RewriteRule \.(gif|jpg|png)$ /images/go-away.png [R,NC]
-In the third example, we redirect the request to an image on some - third-party site.
- -
-RewriteCond %{HTTP_REFERER} !^$
-RewriteCond %{HTTP_REFERER} !www.example.com [NC]
-RewriteRule \.(gif|jpg|png)$ http://other.site.com/image.gif [R,NC]
-Of these techniques, the last two tend to be the most effective - in getting people to stop hotlinking your images, because they will - simply not see the image that they expected to see.
- -