Have you ever wondered how you can deny access to certain folders in your web accessible directory? In this guide I’ll show you how you can limit the folders which can be accessed by your visitors.
This guide is specifically made for those who use wampserver. When I say wampserver it means Windows. So if you’re running Linux, Mac or any other OS then this is not the guide for you.
Let’s start by opening Wampserver. Then left-click on its tray-icon.
Just select any text-editing program that you use if this is your first time opening up httpd.conf
Press ctrl+h on your keyboard to launch the find and replace tool. Then search for something like this:
Allow access to every folder in www directory
For starters you will see something similar to this:
<Directory /> Options FollowSymLinks AllowOverride None Order deny,allow Allow from all //all computers accessing your ip address //will be allowed to access every folder
//in your www directory except phpmyadmin </Directory>
I’ve just added the comment so you’ll understand what’s going on. You don’t have to add it, you might get some error.
Allow access to a folder in www directory for localhost
In this example, the folder that is specified can only be accessed by localhost or the computer with the ip address 127.0.0.1. Your computer for short.
The other computers won’t have access to this folder. Its only you who has access to it. If and only if you’re using: http://localhost from your browser.
<Directory "c:/wamp/www/dompdf/"> Order allow,deny Allow from 127.0.0.1 </Directory>
This will be the output if another computer tries to access the folder that you specified:
For security purposes I only showed you the first and last digit of my current ip address.
Here’s the output if you try to access it using localhost:
Deny from all
This is not very useful because even you won’t have access to the folder. But I’ll still mention it for example purposes.
<Directory "c:/wamp/www/Dropbox/"> Order allow,deny Deny from all </Directory>
This will deny access to the dropbox folder in your www directory.