Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there any ways to deny users to be able to read each *.jpg images from a specific directory? from a file .htaccess

share|improve this question

migrated from Aug 21 '10 at 3:15

This question came from our site for professional and enthusiast programmers.

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:

  1. 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 passes HTTP_REFERER, for privacy reasons).
  2. 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.
share|improve this answer
<Files ~ "\.jpg$">
    Order allow,deny
    Deny from all
    Satisfy all
share|improve this answer
a .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. – Sweet Aug 21 '10 at 3:44
@Sweet Right. I didn't properly read the question. – Artefacto Aug 22 '10 at 17:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.