[thelist] Any apache experts here? - 4rd try

.redstar. redstar at clix.pt
Sun Jul 2 14:22:09 CDT 2000


Hi CDitty,

OK a step by step.

1st - Check that mod rewrite is being loaded. You can't do much with it if
not. This can be accomplished by reading the httpd.conf file a looking for
references to mod_rewrite.
2nd - Now we know mod rewrite is being loaded go to the directory you want
to protect and check if it already has an .htaccess file in it.
3rd - If above is true then open that file as we will be appending changes
to it, if above is not true then create a new file called .htaccess in the
directory.
4rd - (Just to follow your spelling ;) ) Let's assume the files you want to
protect are gif's then write or append the following lines to the .htaccess
file :

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://YOUR.DOMAIN.TLD/.*$ [NC]
RewriteRule .*\.gif$ - [F]

4rd - explanation of above :
	1st line : By default the rewrite engine is off. This will just tell apache
that for this directory we want it on.
	2nd line : the first rewrite condition checks if the http header referer is
being sent. If so we can do our magic.
	3rd line : The decisive rule. Compares if the referer sent by the client
contains your domain name. The end portion between brackets is a flag that's
saying we want a Non Case compare.
	4th line : what to do if the compare fails. In this case the rule say's if
we are requesting anything that contains .gif in it then substitute with
blank. I.E. the client will not get the file. At the end we have another
flag, brackets again, in this case it's F for Forbidden, this sends an
immediate 403 condition back to the requesting agent.

Let's say you also have jpg's you don't want leached. Easy just add another
line under the last one that reads :

RewriteRule .*\.jpg$ - [F]

If you follow the above you'll stop the leaching in most of the cases. the
above will not work only if the browsers don't send the http referer header
so it will work in nearly 100% of the cases.

.redstar.

P.S. : If you get it working to your satisfaction think about writing an
article on Evolt on how to do it. I guess it will be helpful for others
someday.





More information about the thelist mailing list