Ban IP with htaccess

We are assuming you've found this page while trying to learn how to ban ip's with an .htaccess file

Ban IP with htaccess

We cover the following topics in this article.

Whats an .htaccess file?

The original purpose of an .htaccess file was to allow per-directory access control. Password protect a directory or folder. It is now however being used to do much more. example: block ip ranges

.htaccess works on Apache only, and will not do you any good if you are running a windows web server, 90% of web servers online run Apache. If you're not sure ask your hosting provider.

.htaccess Ban Examples

Here are a few rules that are actually in effect on some other site we own.

.htaccess file permissions

Another nifty trick and safeguard is to limit access to certain files that you don't want users to access or download.

In the example below we are deying all users access to the certain filetypes. Those types are; .inc (often used as an includes), sql (database filetypes that may contain backup data), ini (these files often give directions and rules to the php compiler), bak (people often backup files by renaming them somefile.bak)

The code looks like this.

.htaccess file permissions

.htaccess directory access

Showing people your directory content is a weakness. It shows all files even those you don't mean to show. If its in the folder its visible. Example

You can stop this by sticking a blank index.htm file in the folder or simply use the .htaccess file to turn directory grwosing off.

Here is the code for that.

.htaccess directory access

Download the Example!

Similar Topics