How to block images except those in a specific directory

New to mod_rewrite? This is a good place to start.

How to block images except those in a specific directory

Postby krugar » Mon Jan 26, 2004 1:03 pm

After doing some research and following some pointers I learned how to successfully block people from directly linking to my images.

However, I now have the need to allow images in a specific directory to BE ABLE to be linked from outside sites. So in essence, block everything except images in a particular directory. How the heck do I do this? Below is the code that so far works for allowing me to block linked images can anyone help? Thanks in advance.

P.S. The reason why I ask this is that I am including it in the http.conf not a htaccess file. Otherwise I know I would just not have the .htaccess file in the directory I want to leave open.

Code: Select all
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://mydomain.com/.*$     [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mydomain.com/.*$ [NC]
RewriteRule .*\.(gif|GIF|jpg|JPG)$ http://www.mydomain.com/theif.gif [R]
krugar
 
Posts: 2
Joined: Mon Jan 26, 2004 1:01 pm

Postby krugar » Mon Jan 26, 2004 3:44 pm

Heh heh, nevermind. After more research I figured it out. For those wondering:
The following allows images in the /public_images directory to be hot linked and everything else to be blocked. Furthermore, it replaces anything that is blocked with fubar.gif. Hope this helps some of you.

Is this the most optimized way of doing this?

Code: Select all
   RewriteEngine On
   RewriteCond %{REQUEST_URI} !public_images/.*$ [NC]
   RewriteCond %{HTTP_REFERER} .
   RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain\.(net|com) [NC]
   RewriteRule \.(zip|rar|exe|gif|jpe?g)$ /images/fubar.gif [NC,L]
krugar
 
Posts: 2
Joined: Mon Jan 26, 2004 1:01 pm


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 42 guests

cron