restrict access and authenticate login

Overview: To restrict access to a private directory with both IP address restriction and a login and password.

Setup: htaccess and Apache, on M3’s linux hosting.
Objective: Provide authentication and restrict access based on IP address.

WARNING:  Backup up your current .htaccess file first if you have one.  If this procedure produces unwanted results, simply remove the code or rename the file .htaccess to .off.htaccess to disable it.

Change the login example to your own user name and use relevant IP’s to your organisation.  The following is an example.

### Copy Below this line ###

AuthUserFile /home/ftpuser/domain.com/admin/.htpasswd

AuthGroupFile /dev/null
AuthName “IP & Login Required”
AuthType Basic

require valid-user

<FilesMatch \.(?i:gif|jpe?g|png|htm|html|php)$>
Order deny,allow
Deny from all
Allow from 192.168.1
</FilesMatch>

## Copy above this line ###

Copy and paste the above example into your .htaccess file, or create one and upload it to your site’s private directory.

Changes take effect instantly.

This configuration requires the basic understanding of htaccess and how to create a passwd file.  That is reserved for another blog post 🙂

We hope you found this support blog useful.

M3server – world.class.hosting

Leave a Reply