我正在使用通配符 dns 系统,该系统通过单个 Web 应用程序路由所有子域,并根据 URL 的第一部分(X.domain.com,其中 X 是用户名)设置用户 ID。

我现在想编辑我的 htaccess 文件以使用 htpasswd 为特定域启用条件 httpauth。例如如果 url = password.domain.com 启用 httpauth。

我确信这是可能的,但对 htaccess 的了解有限。

最佳答案

您可以使用 SetEnvIf ,这是 Tom Schlick 的 this post 的一个片段。

#allows a single uri through the .htaccess password protection
SetEnvIf Request_URI "/testing_uri$" test_uri

#allows everything if its on a certain host
SetEnvIf HOST "^testing.yoursite.com" testing_url
SetEnvIf HOST "^yoursite.com" live_url
Order Deny,Allow

AuthName "Restricted Area"
AuthType Basic
AuthUserFile /path/to/your/.htpasswd
AuthGroupFile /
Require valid-user

#Allow valid-user
Deny from all
Allow from env=test_uri
Allow from env=testing_url
Allow from env=live_url
Satisfy any

关于.htaccess - 域特定的 htpasswd 条件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2386182/

10-13 09:33