Is there any ways to deny users to be able to read each *.jpg images from a specific directory? from a file .htaccess
2 Answers
So, as I understand it from your second post, what you want is to have photos in a certain directory actually usable on certain web pages, but prevent direct access. The most direct answer is: no, you can't do that — you can't both make something available and simultaneously not available to the same user. There are, however, some things you can do:
- You can use Apache's rewrite rules or another advanced module in .htaccess to check the
HTTP_REFERER
variable and deny access if it isn't your page where you want the images to appear. This will work in many cases, but is easily subverted by a clever end user and could in some cases cause your images to not show up where you do want them (not everything passesHTTP_REFERER
, for privacy reasons). - Put the files somewhere outside of your web root completely, and load them programmaticly (via php or some cgi script). This gives you more flexible control, but still, there's no way for you to tell the difference between a request initiated by loading your legitimate web page and one made by someone cleverly trying to get around the block.
<Files ~ "\.jpg$">
Order allow,deny
Deny from all
Satisfy all
</Files>
-
1a .htaccess shouldn't need the directory tags, it uses the directory it is placed in as the context instead. I think the directory tags here might actually cause a 500 error.– SweetAug 21, 2010 at 3:44
-