Using .htaccess to deny directory access while allowing acce
- coupsan
- A semi-regular
- Posts: 26
- https://www.youtube.com/channel/UC40BgXanDqOYoVCYFDSTfHA
- Joined: Thu Jul 16, 2009 10:10 pm
Using .htaccess to deny directory access while allowing acce
I'd like to use .htaccess to deny entry to particular directories while still allowing access to the files contained in them if directly linked to. In my case, I have a directory that contains a lot of images, but I'd like to prevent people from seeing those images unless I link to them directly. I've tried googling this but the results tend to lead directly to Apache's reference site which is honestly kind of a pain to read.
Re: Using .htaccess to deny directory access while allowing
You are indeed in the right location. I came across the answer to your problem because I also host a lot of content on my site and do not like people being able to browse directories. I am looking for the line to add to your .htaccess file as I type..
Hopefully I will find it soon..
Hopefully I will find it soon..
@Kraze^NFo> Juski has a very valid point
@Juski> Got my new signature, thanks!
@Kraze^NFo> Out of context!
@Juski> Doesn't matter!
@Juski> You said I had a valid point! You can't take it back now! It's out there!
@Juski> Got my new signature, thanks!
@Kraze^NFo> Out of context!
@Juski> Doesn't matter!
@Juski> You said I had a valid point! You can't take it back now! It's out there!
Re: Using .htaccess to deny directory access while allowing
This should help you..
RewriteCond %{HTTP_REFERER} !yoursite.com [NC]
RewriteRule .* - [F]
Your going to need to customize it of course.
RewriteCond %{HTTP_REFERER} !yoursite.com [NC]
RewriteRule .* - [F]
Your going to need to customize it of course.
@Kraze^NFo> Juski has a very valid point
@Juski> Got my new signature, thanks!
@Kraze^NFo> Out of context!
@Juski> Doesn't matter!
@Juski> You said I had a valid point! You can't take it back now! It's out there!
@Juski> Got my new signature, thanks!
@Kraze^NFo> Out of context!
@Juski> Doesn't matter!
@Juski> You said I had a valid point! You can't take it back now! It's out there!
Re: Using .htaccess to deny directory access while allowing
If you use mod_rewrite, you will most likely need this at the top, as well:
RewriteEngine on
RewriteEngine on
Re: Using .htaccess to deny directory access while allowing
Not sure what exactly I'm supposed to customize in those particular lines. The file works--except it also forbids access to the images.
Re: Using .htaccess to deny directory access while allowing
Rereading this, are you just trying to make it so the directory listing doesn't show up? If so, the simplest way is to create a blank index.html file in the folder.
The solution that kraze was giving was meant to defend against external linking.
The solution that kraze was giving was meant to defend against external linking.
Re: Using .htaccess to deny directory access while allowing
Ahaha yes that is what I wanted to do, woops, I can't believe I overcomplicated things that badly. WELP, thanks!