• The Facebook Platform

Results 1 to 1 of 1
  1. #1
    Join Date
    Jan 2010
    Lahore, Pakistan
    Rep Power

    Default How to block users from accessing your site based on their IP address using .htaccess

    Blocking users by IP address is pretty simple with .htaccess.
    So here it is the example:

    Order allow, deny
    Deny from
    Deny from 212.155.
    Deny from
    Allow from all
    Let’s take a look at the code line by line:
    The first line “Order allow, deny” tells the web server the “Order” in which the Allow and Deny directive will be evaluated. It simply says: Give access to all hosts that are not present in the Deny from list and are present in the Allow from list. With allow, deny order Allow list is looked up first and then the web server checks the deny from list. So as we have allow from all – all access is allowed. Then the allowed access is filtered based on the Deny lists. With allow,deny access is disabled by default.

    If we change the order to “deny, allow” then all access is enabled by default and only users in the deny lists are blocked. However as the deny is being processed first allow directives will override any maching settings set in deny directives.
    The default Apache order is deny,allow. So you can skip the first line in your .htaccess file if you do not need to change the order in which the Deny and Allow rules are being evaluated by the web server.
    So to keep the .htaccess simple you can just use:

    Deny from
    Deny from 212.155.
    Basically you can use such rules in your .htaccess file to block a particular user, or a network from accessing your site.
    You can put several IP address in a Deny or Allow rule. For example:

    Deny from
    The IP addresses must be separated by a space or tab.

    You can put entire networks as
    Deny from 212.155.
    This will block all users which IP addresses start with 212.155

    Or to block all access to your site:

    Deny from all
    And then add another line to enable access only for yourself:

    Allow from
    Where “” should be replaced with your computer IP address.

    Last edited by Їийоcёйт Кїllєґ; 01-27-2012 at 03:17 AM.
    Find Me On Social Networks

    Facebook | Twitter | Google+


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts