mod_rewrite help please - blocking direct image linking

mod_rewrite help please - blocking direct image linking

Post by Ali & Charli » Fri, 05 Nov 1999 04:00:00


We wish to block people from directly linking to images on our server. We
basically know how to do this for each Virtual host in the httpd.conf file.
What we would like to know is can we edit the srm.conf so that it covers all
VirtualHosts on the server? It would be a lot easier than having to edit
each VirtualHost section in the httpd.conf .

Here is the snippet of code we are using and if this is possible, could
someone please tell us how to modify this in order for it to work with the
srm.conf. Which one of these should we use?

Also, with the second example below, would this replace the image being
called with a specified image on the server? Maybe someone could be so kind
as to explain to us what the second example does specifically.

Is there also a way when doing this for a single site, to exclude a
directory and allow direct linking to images only in the specified

Example 1
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^*$ [NC]
RewriteRule .*\.gif$        -                                    [F]

Example 2
RewriteCond %{HTTP_REFERER}         !^$
RewriteCond %{HTTP_REFERER}         !.*/foo-with-gif\.html$
RewriteRule ^inlined-in-foo\.gif$   -                        [F]

Thanks In Advance,


1. prevent direct linking - mod_rewrite ?

How could I make it possible to only allow one domain to access
files in a directory?

I tried this, but it didn't really work -
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^*$     [NC]
RewriteCond %{HTTP_REFERER} !^*$ [NC]
RewriteRule .*\.zip$        -                            [F]

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^*$     [NC]
RewriteCond %{HTTP_REFERER} !^*$ [NC]
RewriteRule .*\.tar.gz$        -                           [F]

Anyone have any other ideas please, it would be most appreciated!


Got questions?  Get answers over the phone at
Up to 100 minutes free!

2. Welcome to comp.unix.programmer (v1.18)

3. apache mod_rewrite question: blocking images

4. netatalk and the dreaded nbp_rgstr

5. blocking inline images with mod_rewrite

6. TCP Wrapper and FreeBSD 4.1

7. mod_rewrite & image blocking?

8. Soundblaster 16 PCI woes

9. blocking hotlinked images with mod_rewrite

10. Q: Can a module be set up to prevent direct image linking

11. Blocking outside direct linking problem

12. Statically Linking a Dynamically Linked Binary Image

13. Need a mod_rewrite whiz to help with this..please!