127.0.0.1 Posted February 2, 2007 Share Posted February 2, 2007 Hi, First some background information. My directory hierarchy where images are stored looks like this... img/ img/icons/ img/photos/ img/banners/ I employ a typical rewrite rule to stop outside sites from hotlinking to my images like this and it is placed in the root of my public_html folder... RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?mywebsite.com [NC] RewriteRule \.(jpg|jpeg|png|gif)$ http://www.mywebsite.com/_errors/hotlinking.png [NC,R,L] However, I noticed that when using some proxies to access my site, the user is fed the hotlinking.png. To combat this I want to allow images only in the root of the img directory to be accessed by outside referers, because images in the root img directory are essential to the sites layout. Though images in its sub-directories such as img/icons/, img/photos/, et cetera should still not be allowed access to outside referers. Rather than creating a RewriteRule for each specific directory I was wondering if it was possible to create one RewriteRule placed in the root of the img/ directory that tells mod rewrite to rewrite all images EXCEPT those in the root img/ directory. In other words, to rewrite images in sub-directories of img ONLY, without explicitly having to list each one in the regular expression. I don't know how to do this correctly with regular expressions but I can illustrate what I want using wildcards to clarify what I'd like... */img/*/.gif|png|jpg|jpeg = bad */img/.gif|png|jpeg|jpeg = ok Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.