开发者

Can't get setenv to work in .htaccess

SetEnv doesn't seem to work for me. I tried this in my .htaccess:

SetEnvIf Remote_Addr ^192\.168\.0$ ip_ok
<IfDefine !ip_ok>
  AuthName "Guest Login"
  AuthType Basic
  AuthUserFile /opt/lampp/lib/ok_user开发者_如何学Gos/guests.users
  require valid-user
</IfDefine>

and I had to provide username/password credentials even though my ip is 192.168.0.10 and the server (centos5 / xampp for linux 1.6.8a) is 192.168.0.1

So I tried this:

SetEnv ip_ok
<IfDefine !ip_ok>
  AuthName "Guest Login"
  AuthType Basic
  AuthUserFile /opt/lampp/lib/ok_users/guests.users
  require valid-user
</IfDefine>

but setenv does not set ip_ok, and I still get challenged.

Then I tried this:

SetEnv ip_ok
<IfDefine ip_ok>
  AuthName "Guest Login"
  AuthType Basic
  AuthUserFile /opt/lampp/lib/ok_users/guests.users
  require valid-user
</IfDefine>

and I don't get challenged. Therefore IfDefine is working.

Any ideas why I can't get SetEnv and SetEnvIf to work?? I've googled and read but can't crack it.


<IfDefine> doesn't work like you're thinking. It examines parameters passed to httpd at startup via -Dparameter (or Define in Apache 2.3), not the environment variables.

That's OK though, you should be able to do what you want like this instead:

Order allow,deny
AuthName "Guest Login"
AuthType Basic
AuthUserFile /opt/lampp/lib/ok_users/guests.users
Require valid-user
Allow from 192.168.0
Satisfy Any

TheSatisfy directive, when set to Any, allows you to be granted access if you pass the host verification, or if you've supplied the password.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜