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!
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 184.108.40.206
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 # 220.127.116.11 is a bad IP here deny from 18.104.22.168 allow from all