简体   繁体   English

什么是apht htaccess配置,要求对所有这些URL进行身份验证?

[英]What is apache htaccess configuration to require authentication for all except for these URLs?

What is the htaccess lines/config I would require to ensure that all parts of my site (files & URLs) are protected by authentication, EXCEPT for a given limited set of URLs. 我需要什么htaccess行/配置来确保站点的所有部分(文件和URL)都受到身份验证的保护,但对于给定的有限URL集除外。 For example all except "/api/.*" if this makes sense. 例如,如果可以的话,除“ /api/.*”外的所有内容。

The actually authentication could be like the below, but it's how I wrap this in the directives... 实际的身份验证可能类似于以下内容,但这是我将其包装在指令中的方式...

AuthName "Dialog prompt" AuthType 
Basic AuthUserFile
/home/site/.htpasswd Require
valid-user

thanks 谢谢

You could use SetEnvIf and <IfDefine> : 您可以使用SetEnvIf<IfDefine>

SetEnvIf Request_URI ^/api/ no_auth_req
# If no_auth_req is NOT defined then require authentication
<IfDefine !no_auth_req>
    AuthName "Dialog prompt"
    AuthType Basic
    AuthUserFile /home/site/.htpasswd
    Require valid-user
</IfDefine>

this seems to work: 这似乎可行:

AuthUserFile /home/.htpasswd
AuthName "Password Protected"
authtype Basic
Order Deny,Allow
Satisfy any
SetEnvIf request_uri "/api/" allow_all
Deny from all
Require valid-user
Allow from env=allow_all

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM