homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

Allow and Deny hotlinking code question
Allow and Deny hotlinking code question

 2:17 pm on Jan 14, 2004 (gmt 0)

i have created a .htaccess file in my public web folder wish avoid other sites from hotlinking images from any of the folders on my server .

RewriteEngine on
# redirect images
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?example\.com/ [NC]
RewriteRule \.(gif?jpe?g?)$ /no.$1 [NC,L]

This works well.

Now my question is i want to allow hotlinking from one folder with few banners now what new .htaccess do i have to make so that hotlinking is allowed from this folder only and all others are protected.

this is my server

var/home/web/htdocs/ .htaccess with anti hotlink code
var/home/web/htdocs/images/ this is auto protected by above htaccess file
var/home/web/htdocs/faq/icons/ this one is protected to ..

now i made a folder at:

now what sort .htaccess file do i have to put inside the folder /protect/ to allow hotlinking from this folder only so i can put some banners inhere ....

pls advise

[edited by: DaveAtIFG at 4:52 pm (utc) on Jan. 14, 2004]
[edit reason] Revised URL pattern to "example" [/edit]



 6:47 pm on Jan 14, 2004 (gmt 0)


Simply add another RewriteCond to your existing code in /htdocs:

RewriteEngine on
# redirect images except banners
[b]RewriteCond %{REQUEST_URI} !^/faq/icons/protect/[/b]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example\.com/ [NC]
RewriteRule \.(gif¦jpe?g?)$ /no.$1 [NC,L]



 7:25 pm on Jan 14, 2004 (gmt 0)

Hi Jim thanks for your reply ..

can you give me more details on what;
RewriteCond %{REQUEST_URI}!^/faq/icons/protect/

ecactly will do?

will it exclute this fodler protect or will it only stop hotlinking in folder protect?

what i need is that all folders are antihotlink protected ecept from one folder ...


 7:21 pm on Jan 15, 2004 (gmt 0)

It stops the following RewriteRule from being applied if the image is in that /faq/icons/protect/ directory. Hopefully, it will do what you want to do! ;)



 10:26 pm on Jan 15, 2004 (gmt 0)

excellent i go play with the code and test ..
i will et you knwo if worked ..

thx ;)

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved