Drupal: .htaccess Access Deny
August 21, 2014 – 7:59 am | No Comment

In this article I will tell how to forbid access to certain resources for some clients. The instructions will include descriptions of different directives.

Read the full story »
CSS Templates

Contain reviews and news about CSS Templates.

Freebies

Contain freebies such as icons, graphics, headers and images for your websites.

Fun Stuff

Contains other fun stuff for entertainment or interesting site showcase.

How-To

Contain technical elaborations on some specific workarounds or common tweak.

Joomla Templates

Contains reviews and news about Joomla templates.

Home » How-To

Drupal: .htaccess Access Deny

Submitted by on August 21, 2014 – 7:59 amNo Comment

In this article I will tell how to forbid access to certain resources for some clients. The instructions will include descriptions of different directives.

First let’s speak about Order directive of .htaccess file of Apache server.

Description: Sets order of work of Deny and Allow directives. Order can take the following values: [Deny , Allow] or [Allow , Deny].

Syntax: the default state:

Order Deny,Allow

 

Deny directive

Description: Denies access to certain resources for specified clients.

Syntax:

Deny from all|host

host can take values of IP address or host name.

 

Allow directive

Description: Allows access to certain resources for specified clients.

Syntax:

Allow from all|host

host can take values if IP address or host name.

 

Example: .htaccess access deny for all clients

Order Deny,Allow

Deny from all

Example: .htaccess access_ allow_ for a certain IP address and host.

Order Deny,Allow

# access deny to a resource for all clients

Deny from all

# allow for the following IPs only

Allow from local.

Allow from 100.99.99.1, 100.99.99.2

Example: .htaccess access_ deny_  for a certain IP address and host.

Order Allow,Deny

#allow all users to login to the server

Allow from all

Deny from local.

Deny from 100.99.99.1, 100.99.99.2

If you need to deny access for entire network (100.99.99.1 – 100.99.99.255) you should set a combination of the first  lems: 100.99.99

 

Files directive

Description: : denies access to a certain file.

Example: access deny to a file with passwords (.htpasswd) for all users except 100.99.99.1 и 2

<Files “.htpasswd”>

Order Deny,Allow

Deny from all

Allow from 100.99.99.1, 100.99.99.2

</Files>

In the example below, we will deny entering to the resource for users whose IPs are 100.99.99.1, 100.99.99.2 using GET method (.htaccess ip):

<Limit GET>

Order Allow,Deny

Deny from 100.99.99.1, 100.99.99.2

Allow from All

</Limit>

We denied user with IP = 100.99.99.1 viewing the site. If we replace 100.99.99.1 with 100.99.99, access will be denied for the entire network of C class.

Here is one more example: access deny to a group of files. In the example below, access is denied to files with “lib” and “pm” extensions and for all users except 100.99.99.1

<FilesMatch “\.(lib|pm)$”>

# или например : <FilesMatch “\.(gif|jpe?g|png)$”>

Order Deny,Allow

Deny from all

Deny from 100.99.99.1

</FilesMatch>

That’s all for now.

Good luck!

Leave a comment!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.