.htaccess配置允许从某些IP访问,并且无需访问.htaccess即可登录

时间:2014-02-04 07:31:32

标签: .htaccess mod-rewrite

我正在尝试为文件夹创建.htaccess文件。来自某些IP和登录用户(来自某些组)的用户应该能够访问该文件夹中除.htaccess文件(所有人都无法访问)之外的所有文件。我只是被困在这里。这是我到目前为止所得到的:

<FILES .htaccess>
order allow,deny
deny from all
</FILES>

Order allow,deny
Deny from all
# Location of users file
AuthUserFile /etc/httpd/conf/.htpasswd
# Location of usergroups file
AuthGroupFile /etc/httpd/conf/.htgroup
# Name of the prompt
AuthName "Enter password"
AuthType Basic
# Required usergroup to access content
Require group group1
# Allow access from IP 1 without login
Allow from xxx.yyy.zzz.www
# Allow access from IP 2 without login
Allow from jjj.kkk.lll.mmm
Satisfy any

Options +Indexes

任何帮助都将受到高度赞赏!

1 个答案:

答案 0 :(得分:0)

这是(最终)工作解决方案:

<FilesMatch "^(?!\.htaccess).*$">

AuthType Basic
# Name of the prompt
AuthName "Enter user name andd password"
# Users file location
AuthUserFile /etc/httpd/conf/.htpasswd
# Usergroups file location
AuthGroupFile /etc/httpd/conf/.htgroup
# Required group for authentication
Require group group_name

Order deny,allow
Deny from all
# Allow access from this IP without login
Allow from aaa.bbb.ccc.ddd
Satisfy any

</FilesMatch>