CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: General Discussions: General Questions:
Rewrite Rule to block specific referer?

 



James
Troll

Aug 30, 2002, 9:57 AM

Post #1 of 2 (2790 views)
Rewrite Rule to block specific referer? Can't Post

This is an image-leeching-prevention question. I know I can use the code pasted below in my .htaccess file to prevent all external domains from leeching images.

This only allows image-linking from mydomain.com. Problem is I need to turn that around and deny image-linking from a single, specific domain (ebay.com), while allowing image-leeching from all other domains. We have affilliates who are authorized to "leech" banners. (Or maybe there's a way to exclude the banner directory from the rewrite rule above?)

Any ideas?


Code
 RewriteEngine on 
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain.com/.*$ [NC]
RewriteRule \.(gif|jpg)$ - [F]




Jasmine
Administrator

Sep 15, 2002, 11:51 PM

Post #2 of 2 (2768 views)
Re: [James] Rewrite Rule to block specific referer? [In reply to] Can't Post

Have more fun than just making a broken image in ebay.com. Here's code that will put an image of your choosing in there instead. Sly


Code
RewriteEngine on  
RewriteCond %{HTTP_REFERER} ^http://(www\.)?ebay.com/.*$
RewriteRule \.(gif|jpg)$ /stopstealing.gif [NC]


Or if you needed to deny multiple domains, you can use [url=http://httpd.apache.org/docs/mod/mod_rewrite.html#RewriteCond][OR]:


Code
RewriteEngine on  
RewriteCond %{HTTP_REFERER} ^http://(www\.)?ebay.com/.*$ [OR]
RewriteCond %{HTTP_REFERER} ^http://dummy.hypermart.com/.*$
RewriteRule \.(gif|jpg)$ /stopstealing.gif [NC]


Note that the RewriteCond and RewriteRule uses regular expressions, and that the period means "any single character". So while the period between ebay and com will match as intended (because the way the rest of the expression is structured), it's important to realize that the . is actually a regular expression metacharacter that will match a single character. In this case, it'll match the period.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives