PDA

View Full Version : Apache Directive to Block Image Linking


DantePasquale
21st July 2009, 20:27
Hi All,

I'm still running ISPConfig2 and have some working Apache Directives and want to add another. Specifically to rewrite links to images that I can't grant permission to outside sites to link to. For example, if a site links to http://www.cocoanet.us/images/image1.jpg, I want to route that link to another image http://www.cocoanet.us/images/notallowed.jpg.

So, I got on the url rewrite forum and they have a recipe that looks promising, but it doesn't seem to work. Here's the entire apache directives entry and the one I'm having problems with is hightlighted:

<IfModule mod_rewrite.c>
<Directory /var/www/web8/user/web8_dantepasquale/web/blog>
RewriteEngine On
RewriteBase /~web8_dantepasquale/blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /~web8_dantepasquale/blog/index.php [L]
</Directory>
<Directory /var/www/web8/user/web8_dantebell/web/blog>
RewriteEngine On
RewriteBase /~web8_danteell/blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /~web8_dantebell/blog/index.php [L]
</Directory>
<Directory /var/www/web8/user/web8_bcbgirl/web/blog>
RewriteEngine On
RewriteBase /~web8_bcbgirl/blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /~web8_bcbgirl/blog/index.php [L]
</Directory>
<Directory /var/www/web8/web/images>
RewriteCond %{HTTP_REFERER} ^(http://(www\.)?cocoanet\.us(/.*)?)?$ [NC]
RewriteRule .\.(jpg|png)$ - [F,L] /var/www/web8/web/images/notallowed.jpg [R,L]
</Directory>
</IfModule>

My understanding is that as long as the referer is not my own website, then the rewrite module should push the image "notallowed.jpg" to that site. My images are under the /var/www/web8/web/images directory. Am I screwing this up by providing the full path?

Thanks, Danté

falko
22nd July 2009, 17:37
Change
RewriteCond %{HTTP_REFERER} ^(http://(www\.)?cocoanet\.us(/.*)?)?$ [NC]

to
RewriteCond %{HTTP_REFERER} !^(http://(www\.)?cocoanet\.us(/.*)?)?$ [NC]