.htaccess deny from all – restrict directory access

You may have a folder on your server that you don’t want anyone to access, especially if it is where you store sensitive information or digital download products. The best way to block anyone from being able to view a directory on an Apache server is by using the .htaccess file.

To deny all requests for the restricted directory or folder, prepare a .htaccess text file in that directory and put the following code in it:

deny from all

It’s as simple as that!

Allow Access From A Certain IP Address

This would be best used if you have a CMS or administration system for your website and want to block the public from getting in. For this to work you must have a static, permanent IP address otherwise you will have to keep updating the code each time you log on to the internet.

Place the following code in your directory’s .htaccess file (replacing the IP with your IP address):

order deny, allow
deny from all
allow from

Deny Access From Certain IP

So by now you have probably got the idea. To allow all visits except from a few identified spam bots (or other undesired visitors), just reverse the deny and allow order like this:

order allow, deny
# is a bad IP here
deny from
allow from all
Free Graphics, Icons, Tutorials
Free Graphics Free Christmas Vector Icon Graphics Pack 2017Free Fitness Vector Icons Graphics PackFree Camping Vector Graphics PackFree Summer Graphics PackFree File Icon PackFree Fast Food Vector Graphics
Sharing is caring...
Like & Follow
Share the love, share this page! Facebook Twitter Digg Reddit LinkedIn Pinterest Email
Close [X]
The Web Taylor
1000 Lakeside North Harbour Portsmouth, Hampshire PO6 3EN
02392 123358