如果查询字符串包含参数,我试图允许用户使用wordpress wp-admin索引页面。我正在设置env变量以允许它们访问。这就是我的htaccess文件的样子
RewriteEngine on
RewriteCond %{QUERY_STRING} !^author=1
RewriteRule ^ - [E=NO_AUTH:1]
AuthName "Staff Authorization Required"
AuthType Basic
AuthUserFile /usr/bin/.htpasswd
<Files "index.php">
Order Deny,Allow
Deny from all
Require user newagenumber
Allow from env=NO_AUTH
</Files>
Options -Indexes
到目前为止,每个人都会出现授权对话框。请帮忙:|
答案 0 :(得分:3)
这不起作用,因为Apache在mod_auth
之前执行了mod_rewrite
模块,因此在基本身份验证指令运行时未设置NO_AUTH
。
不幸的是,这种行为并不那么简单。
以下是一个将mod_rewrite
,mod_setenvif
和mod_auth
组合在一起的解决方案:
RewriteEngine On
RewriteBase /wp-admin/
RewriteCond %{QUERY_STRING} (?:^|&)(author=1)(?:&|$) [NC]
RewriteRule ^(index\.php)?$ index.php/%1 [NC]
# set SECURED var to 1 if URI is /index.php/200
SetEnvIfNoCase Request_URI "/index\.php/(author=1)" NO_AUTH
AuthType Basic
AuthName "Login Required"
AuthUserFile /full/path/to/passwords
Require user newagenumber
Order Deny,Allow
Deny from all
Allow from env=NO_AUTH
Satisfy any