apache密码保护特定URL
我需要对特定URL进行密码保护,例如,任何人都可以访问index.php,但一旦他们添加参数或“GET”变量,我必须要求有效的用户 index.php->sweet index.php?prev=1->require valid user您可以使用get变量上的方法,例如:apache密码保护特定URL,apache,.htaccess,passwords,Apache,.htaccess,Passwords,我需要对特定URL进行密码保护,例如,任何人都可以访问index.php,但一旦他们添加参数或“GET”变量,我必须要求有效的用户 index.php->sweet index.php?prev=1->require valid user您可以使用get变量上的方法,例如: if (isset($_GET['prev'])) { //load password input form } 有趣的问题 这里有一个解决方案: <Location /fakeindex.php> Ord
if (isset($_GET['prev'])) {
//load password input form
}
有趣的问题
这里有一个解决方案:
<Location /fakeindex.php>
Order Deny,Allow
Deny from All
Allow from env=REDIRECT_STATUS
AuthType Basic
AuthUserFile /pathto/htpasswd/file/passwords.secret
AuthName This is an example auth
Require valid-user
</Location>
<Directory /path/to/doc/root>
Order allow,deny
allow from all
RewriteEngine On
RewriteCond %{QUERY_STRING} .
RewriteCond %{REQUEST_URI} index.php
RewriteRule .* fakeindex.php [L,QSA]
</Directory>
是否存在阻止直接访问/fakeindex.php的方法(但实际上谁希望强制直接访问受保护区域)。这是可选的
关键的一点是这些条件规则检测一个非空的查询字符串和一个对index.php的请求:
RewriteCond %{QUERY_STRING} .
RewriteCond %{REQUEST_URI} index.php
如果它们符合规则:
RewriteRule .* fakeindex.php [L,QSA]
在内部将请求重定向到/fakeindex.php,将查询字符串保留在QSA中。然后应用位置,并在该位置上进行身份验证。wow!非常感谢!一个q,但是-这不能用在.htaccess中,因为
RewriteRule .* fakeindex.php [L,QSA]