允许IP地址而无需身份验证

reb*_*ion 27 authentication .htaccess

我已经建立了一个目前正在进行中的网站.我正在使用外部SMS网关,需要访问我的服务器上的脚本.但是,我已经为普通用户设置了基本的用户名和密码验证,但是SMS网关无法通过它.

如何在不验证自身的情况下允许单个IP通过身份验证,并拒绝所有未经身份验证的其他用户?

这是我的.htaccess档案:

Order allow,deny
Allow from all
AuthType Basic
AuthUserFile /www/.site_htpasswd
AuthName "Protected Area"
require user admin
Run Code Online (Sandbox Code Playgroud)

reb*_*ion 44

刚刚在JoseK的帮助下找到了:

Order deny,allow
Deny from all
AuthType Basic
AuthUserFile /www/.site_htpasswd
AuthName "Protected Area"
require valid-user
Allow from 1.2.3.4
Satisfy Any
Run Code Online (Sandbox Code Playgroud)

  • 这适用于Apache 2.2.Apache 2.4有[新语法](http://stackoverflow.com/a/27209938/878514). (2认同)

fba*_*ien 29

更新:例如Apache 2.4, ,Order,Allow,DenySatisfy指令不应再使用.所以新的语法是:

AuthType Basic
AuthUserFile /www/.site_htpasswd
AuthName "Protected Area"

<RequireAny>
    Require ip 1.2.3.4
    Require valid-user
</RequireAny>
Run Code Online (Sandbox Code Playgroud)