Forum Topic: block ouside direct access to subdirectory but allow index access

Forum: .htaccess Forum : Redirecting • Posted by dennis guess • Updated:

I have a subdirectory www.mydomain\subdirectory that has a number of pdf files in it. I would like to block direct URL access downloads like www.mydomain\subdirectory\myfile.pdf. I would also like to give permission to another subdirectory2 in mydomain to have access. In other words I would like access to subdirectory only to be from www.mydomamain\subdirectory2. Which htaccess commands shuld I use or please give me the reference pages in your book. thanks

1 Reply to “block ouside direct access to subdirectory but …”

Jeff Starr
Posted by Jeff Starr

Hi Dennis,

Password-protecting the PDF folder will keep everyone out while allowing the server access from another directory, say from a PHP script. Check out chapter 7.4 for how-to password-protect, and then once that's in place verify that your script is able to access the protected directory. Should work fine (it's how I do it at a number of sites), let me know if any issues, I'm here to help.