Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 stackoverflow.com Aug 21 '10 at 3:15

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

add comment

2 Answers

<Files ~ "\.jpg$">
    Order allow,deny
    Deny from all
    Satisfy all
</Files>
share|improve this answer
1  
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
add comment

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
add comment

Your Answer

 
discard

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