2.7.1.1.6. Access restriction by IP address

You can also restrict access through relevant section control panel.

Attention!

Directives in .htaccesswill not work for files with extensions specified in list of static files.

Directives must be placed in a file .htaccesslocated in the directory of the site to which you want to restrict access. Restricted visitors will receive answer 403.

In the example directives:

  • XXX.XXX.XXX.XXX — The IP address for which you want to allow or deny access.
  • admin/login/ — page to which access will be restricted. The full address will look like this − http://example.com/admin/login/.
  • Specify multiple addresses at once in directives Order can be done in several ways:
    • Separate addresses - each address with a new line in the form Allow from XXX.XXX.XXX.XXX.
    • Address ranges:
      • As a subnet mask (for example, 123.213.0.0/16, which corresponds to the address range 123.213.0.0-123.213.254.254).
      • With an asterisk symbol * for part of the address (for example, 123.213.*.*).
  • Specify multiple addresses at once in directives Rewrite possible with the help regular expressions:
    • Separate addresses:
      • As (a|b|c), where a, b and c they are different addresses.
      • Each address on a new line in the form RewriteCond %{REMOTE_ADDR} !^XXX\.XXX\.XXX\.XXX$.
    • Address ranges — in the form \d{1,3} instead of one of the IP address blocks (for example, !^123\.213\.\d{1,3}\.\d{1,3}$, which corresponds to the address range 123.213.0.0-123.213.254.254).

Restricting access to the entire site using directives Order Allow,Deny:

Order Deny,Allow
Deny from all
Allow from XXX.XXX.XXX.XXX

Limiting the page using directives Rewrite:

RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^XXX\.XXX\.XXX\.XXX$
RewriteRule ^admin/login/? - [F,NC]

Site-wide restriction using directives Order Allow,Deny:

Order Allow,Deny
Allow from all
Deny from XXX.XXX.XXX.XXX

Limiting the page using directives Rewrite:

RewriteEngine on
RewriteCond %{REMOTE_ADDR} ^XXX\.XXX\.XXX\.XXX$
RewriteRule ^admin/login/? - [F,NC]
Content