Forum Moderators: phranque
I use this code in my htaccess file to stop hotlinkers;
RewriteEngine on
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://MyWebSite.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://wwWebmasterWorldebSite.com/.*$ [NC]
RewriteRule .*\.(gif¦GIF¦jpg¦JPG)$ [MyWebSite.com...] [R]
My question is if i add cgi¦pl to the RewriteRule .*\ line
would it then also automaticly stop other sites from using my cgi scripts?
i were thinking of chanhing the RewriteRule to :
RewriteRule .*\.(gif¦GIF¦jpg¦JPG¦cgi¦pl)$ [MyWebSite.com...] [R]
Othewr sites should be allowed to link tosome of my cgi scripts.but they may not runthem from there domains.
Will this work?
i look forward to your comments
You can make the RewriteRule case-insensitive using the [NC] flag, and you probably should add an [L] flag. Since there is no start anchor, ".*" at the beginning of the pattern is no needed. Redirecting transparently (omitting the [R] flag) prevents them from easily figuring out what happened.
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?MyWebSite\.com/ [NC]
RewriteRule \.(gifŠjpe?g?ŠcgiŠpl)$ /no.gif [NC,L]
I would suggest handling your cgi and pl filetype blocks separately from the images. It will make no sense to a browser for a script request to be redirected to a .gif image file. Actually, I suggest creating a "dummy" file for each image type, and then using a rule like this:
RewriteRule .*\.(gifŠjpe?g?)$ /no.$1 [NC,L]
Alternately, you can just block them all and return 403-Forbidden
RewriteRule .*\.(gifŠjpe?g?ŠcgiŠpl)$ - [NC,F]
Summing up, with all the bells and whistles, you'd have:
RewriteEngine on
# redirect images
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?MyWebSite\.com/ [NC]
RewriteRule \.(gifŠjpe?g?)$ /no.$1 [NC,L]
# block scripts
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?MyWebSite\.com/ [NC]
RewriteRule \.(cgiŠpl)$ - [NC,F]
Jim