.htaccess: allow anyone from one IP but require password from everywhere else
November 28, 2009
Snippets | Web Building

If you want your linux-hosted site to be accessible by anyone coming from a particular IP address, as say from within a corporate firewall, but also accessible from anywhere else as long as they authenticate with username and password, use this formula in the .htaccess file for the directory:

#this section may need to be modified to suit your password authentication setup:
AuthUserFile "/home/pathTo/.htpasswds/directory_name/passwd"
AuthType Basic
AuthName "webroot"
require valid-user
# allow users from inside firewall
Allow from 111.222.33
Satisfy Any

Ads by Google

Posted by ellen at November 28, 2009 10:47 AM


If you aren't sure what the path to the passwords file is on your server, use Cpanel to password protect the directory. It will add the correct path to the .htaccess file in the directory, then you can add the rest of the snippet above.

If Cpanel is available, you can use it to add the users and passwords as well.

References "Allow from IP address with no password prompt, and also allow from non-Ip address with password prompt:"

  • Evolt.org: Ultimate htaccess Examples


  • Ads by Google


    Ads by Google

     RSS   |   Contact Me


    Ads by Google