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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

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



Aug 30, 2002, 9:57 AM

Post #1 of 2 (3383 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 Problem is I need to turn that around and deny image-linking from a single, specific domain (, 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?

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


Sep 15, 2002, 11:51 PM

Post #2 of 2 (3361 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 Here's code that will put an image of your choosing in there instead. Sly

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

Or if you needed to deny multiple domains, you can use [url=][OR]:

RewriteEngine on  
RewriteCond %{HTTP_REFERER} ^http://(www\.)?*$ [OR]
RewriteCond %{HTTP_REFERER} ^*$
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