[英]Combine basic auth and redirect in .htaccess?
Following situation: 以下情况:
any idea how to do that? 知道怎么做吗?
I tried to use one htaccess file where i added some redirection rules and the basic auth stuff. 我尝试使用一个htaccess文件,在其中添加了一些重定向规则和基本身份验证内容。 But I never got the redirection rules to work correctly.
但是我从来没有重定向规则正常工作。 Seamed the auth stuff is overwriting the redirection rules.
Seamed auth内容正在覆盖重定向规则。 Could that be?
可以吗?
I use the following code for the Authentication 我将以下代码用于身份验证
AuthName "Restricted"
AuthType Basic
AuthUserFile //is/htdocs/www/subfolder1/.htpasswd
AuthGroupFile /dev/null
require valid-user
You can use this code in your DOCUMENT_ROOT/SubFolder1/.htaccess
file: 您可以在
DOCUMENT_ROOT/SubFolder1/.htaccess
文件中使用以下代码:
RewriteEngine On
RewriteCond %{REMOTE_ADDR} !^(192\.168\.0\.10|192\.168\.0\.20)$
RewriteRule ^$ http://www.mydomain.tld/ [L,R]
SetEnvIf Remote_Addr ^(192\.168\.0\.10|192\.168\.0\.20)$ DOAUTH
AuthName "Restricted"
AuthType Basic
AuthUserFile //is/htdocs/www/subfolder1/.htpasswd
AuthGroupFile /dev/null
require valid-user
Satisfy any
Order allow,deny
Allow from all
Deny from env=DOAUTH
SetEnvIf
is needed because mod_auth
runs before mod_rewrite
hence env set by mod_rewrite
cannot be used mod_auth
. SetEnvIf
是需要的,因为mod_auth
之前运行mod_rewrite
因此ENV通过设置mod_rewrite
不能使用mod_auth
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.