title: How to deny direct access to a folder using htaccess
body: <p>My website is all about images. So I want to find a way to prevent direct access to images folder using (I guess) .htaccess.
  From what I've read one way is to move the images folder out of the web-root and then add an .htaccess file with the following code: </p>
  
  <pre><code>deny from all
  </code></pre>
  
  <p>So here are my questions: </p>
  
  <ul>
  <li><p>Will I have any problems if I don't move the folder outside the web-root? Because I will have to make a lot of changes to the code in all pages. What's the logic behind moving the images folder outside the web-root? </p></li>
  <li><p>Is there any other safe way to do this? I am worrying that If add .htaccess that will deny access to all images then I won't be able to share my pages and use the images in them.</p></li>
  </ul>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>What about if I use the following code that will prevent hotlinking of my images but will allow it to specific websites. </p>
  
  <pre><code>RewriteEngine on
  RewriteCond %{HTTP_REFERER} !^$
  RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourdomain.com [NC]
  RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yordomain2.com [NC]
  RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yordomain3.com [NC]
  RewriteRule \.(jpg|jpeg|png|gif)$ http://page-to-redirect [NC,R,L]
  </code></pre>