Apache 当setenif被重写为index.php时,如何将其与Request_URI一起使用?
我们有一个drupal网站Apache 当setenif被重写为index.php时,如何将其与Request_URI一起使用?,apache,.htaccess,setenvif,Apache,.htaccess,Setenvif,我们有一个drupal网站a.com,受密码保护。不过,我希望所有的a.com/api/…uri都不是。所以我读过关于setenif的setenif: AuthName "Stage" AuthType Basic AuthUserFile ~/.htpasswd SetEnvIf Request_URI ".*data_sheets.*\.pdf" noauth SetEnvIf Request_URI "/api/.+" noauth SetEnvIfNoCase Request_Metho
a.com
,受密码保护。不过,我希望所有的a.com/api/…
uri都不是。所以我读过关于setenif的setenif
:
AuthName "Stage"
AuthType Basic
AuthUserFile ~/.htpasswd
SetEnvIf Request_URI ".*data_sheets.*\.pdf" noauth
SetEnvIf Request_URI "/api/.+" noauth
SetEnvIfNoCase Request_Method OPTIONS noauth
Order Deny,Allow
Deny from all
Require valid-user
Allow from env=noauth
Satisfy Any
不过,/api/foobar
uri仍在请求密码。由于它是一个Drupal网站,在anubhava的帮助下,我们发现它与index.php如何处理请求有关
如何处理
编辑
添加
RewriteCond %{REQUEST_URI} ^/api/ [NC]
RewriteRule ^ - [E=noauth]
紧接着
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]
没有帮助这对我有用:
AuthName "Stage"
AuthType Basic
AuthUserFile /var/www/html/.htpasswd
SetEnvIf Request_URI ".*data_sheets.*\.pdf" noauth
SetEnvIf Request_URI "/api/.+" noauth
SetEnvIfNoCase Request_Method OPTIONS noauth
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/api/
RewriteRule ^ - [E=noauth:1]
Order Deny,Allow
Deny from all
Require valid-user
Allow from env=noauth
Allow from env=rewritten
Satisfy Any
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ /index.html [L]
我迟到了两年,但我已经对正在发生的事情以及你如何应对做出了一个明确的决定。简短版本: 重写规则由子请求完成。SetEnvIf模块不继承子请求中的REQUEST_URI变量。在这些子请求中,您的noauth变量最终是未定义的
将
和
块与mod_core的SetEnv
一起使用,而不是依赖mod_setenif。我刚刚在我的Apache 2.4中尝试了这个代码片段,它运行良好,在访问/api/foobar/
@anubhava时没有请求auth您是对的,删除所有其他htaccess内容会给我一个“未找到”的提示。我想我必须改变这个问题,而不是RewriteCond%{REQUEST\u URI}^/api/[NC]
你能试试RewriteCond%{the\u REQUEST}/api/[NC]吗
问题是我无法在Apache上重现此问题。您需要使用FallbackResource/index.php
而不是使用mod_rewrite.s\s
有意义吗?这不是一个空白吗?<代码> Type请求< /代码>包含浏览器发送给服务器的完整HTTP请求行(例如,代码> GET/DIXX.HTTP/1.1代码/代码>),因此在%{REQUEST_URI}
的情况)