.htaccess block image

Whether you are using Linux on the desktop or as a server, it's still good that you're using Linux. Linux related questions go here.

Moderator: General Moderators

Post Reply
me666
Forum Commoner
Posts: 87
Joined: Wed Oct 08, 2008 5:04 pm

.htaccess block image

Post by me666 »

hi guys.. on my host i have a folder named 'include' which holds all files needed for scripts and so on aswell as all my images in a subfolder 'img'
i have used a .htaccess file to block access from these folders/files using the following code

Code: Select all

deny from all
but now my images do not show within my pages.
i basically want to block people from viewing the files and images directly but can view them within a page.
meaning if someone typed into the address bar http://my-site.com/include/logo.jpg they wont be able to see it but on my homepage using <img src="/include/img/logo.jpg"> it will display
thanks :)
me666
Forum Commoner
Posts: 87
Joined: Wed Oct 08, 2008 5:04 pm

Re: .htaccess block image

Post by me666 »

hi again,
still looking for a solution on this. i have found the hotlinking to file types though.
only thing is, i get an error 500 posible bad .htaccess file message. can anyone tell me where any errors in my file may be. here is my .htaccess file

Code: Select all

<Files .htaccess>
order allow,deny
deny from all
</Files>

ErrorDocument 404 /404.html
ErrorDocument 403 /403.html

Options -Indexes

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^ http://(www.)?my-website.domain.com/.*$ [NC]
RewriteRule \.(gif|jpg|jpeg|png|JPG|JPEG|GIF|PNG)$ - [F]
thanks guys :)
wanderingSamurai
Forum Newbie
Posts: 1
Joined: Mon Jul 19, 2010 3:31 pm

Re: .htaccess block image

Post by wanderingSamurai »

One way of doing this will be to use authentication what you can do is inside the httpd.conf file add the directory tag here's a link to the apache documentation
http://httpd.apache.org/docs/2.0/howto/auth.html
Post Reply