Apache Directive to Block Image Linking

Discussion in 'Installation/Configuration' started by DantePasquale, Jul 21, 2009.

  1. DantePasquale

    DantePasquale Member HowtoForge Supporter

    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:

    Code:
    <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>
      [B]<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>[/B]
    </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é
     
  2. falko

    falko Super Moderator ISPConfig Developer

    Change
    Code:
    RewriteCond %{HTTP_REFERER} ^(http://(www\.)?cocoanet\.us(/.*)?)?$ [NC]
    to
    Code:
    RewriteCond %{HTTP_REFERER} [B][COLOR="Red"]![/COLOR][/B]^(http://(www\.)?cocoanet\.us(/.*)?)?$ [NC]
     

Share This Page