Home HTACCESS Deny or Allow Certian IP Addresses

Deny or Allow Certian IP Addresses

In some situations, you may want to only allow people with specific IP addresses to access your site (for example, only allowing people using a particular ISP to get into a certain directory) or you may want to ban certain IP addresses (for example, keeping disruptive members out of your message boards). Of course, this will only work if you know the IP addresses you want to ban and, as most people on the internet now have a dynamic IP address, so this is not always the best way to limit usage.

You can block an IP address by using:

deny from 000.000.000.000

where 000.000.000.000 is the IP address. If you only specify 1 or 2 of the groups of numbers, you will block a whole range.

You can allow an IP address by using:

allow from 000.000.000.000

where 000.000.000.000 is the IP address. If you only specify 1 or 2 of the groups of numbers, you will allow a whole range.

If you want to deny everyone from accessing a directory, you can use:

deny from all

but this will still allow scripts to use the files in the directory.

Examples:

Allow access from a certain IP address:

order allow deny
deny from all
allow from <your_IP>

In this case, <your_IP> stands for a specific address.

For example:

order allow deny
deny from all
allow from 192.126.12.199

Forbid access from a certain IP address:

order allow deny
deny from all
deny from <your_IP>

Using <your_IP> is similar to the example above.

Forbidding a group of files by mask:

<Files ~ "\.(inc|sql|...other_extensions...)$">
order allow,deny
deny from all
</Files>

Defines access to a file by its extension. For example, forbidding web visitors to access files with the “inc” extension:

<Files ~ "\.(inc)$">
order allow,deny
deny from all
</Files>

You may also like

Leave a Comment