How to Make A Directory Forbidden

by 8 replies
9
I have a website that has several directories that are not using wordpress.

Is there anyway to make these directories forbidden while allowing access to the files inside the directories?

For example I have a site where I give a way a free report at:

mysite.com/report/report.pdf

I would like to make the "report" directory forbidden in case anyone tries to sees what else is in side mysite.com/report

Thanks for your input
#website design #directory #forbidden #make
  • You can certainly get fancy with .htaccess, but the easiest thing to do to meet your needs is to publish a simple index.php file, saying pretty much anything you'd like.
    • [ 1 ] Thanks
    • [1] reply
  • Sometimes the simple answer is the best. I would only add to David's answer that I am not aware of any reason it has to even be a php file - an index.html should do the trick just as nicely.

    When you do decide to get fancier, I know aMember Pro can protect directories outside of Wordpress for you.
    • [1] reply
    • Correct. I just got into the habit of always using PHP even in absolutely trivial cases, since then you can always add (unanticipated) features later. For example, the OP might decide to add a redirect in the future, and will be able to do so without changing filenames. But sure, there's no real reason that it has to be PHP.
      • [1] reply
  • That is deliciously devious
    • [1] reply
    • Actually I got the idea from someone who suggested sending them to a bad neighborhood or to Google, but I decided I didn't want to piss off G or some hackers.

      This seems to me to be the best approach as far as minimal impact on my host. The usual 403 approach ends up writing an error to the Apache error log file, extra work and clutter to filter out if you are trying to resolve other issues by looking at the log file.

      I do the same with my .htaccess to discourage bandwidth sucking spiders

      Code:
      RewriteCond %{HTTP_USER_AGENT} Baidu [NC,OR]  
      RewriteCond %{HTTP_USER_AGENT} Yandex [NC,OR] 
      RewriteCond %{HTTP_USER_AGENT} YYSpider [NC]
      RewriteRule .* http://%{REMOTE_ADDR} [L,R=301]
      Works for the whole domain WordPress or not, and it keeps WordPress from ever seeing the traffic, unlike a plugin which impacts heavily on the server.

Next Topics on Trending Feed