Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache 当setenif被重写为index.php时,如何将其与Request_URI一起使用?_Apache_.htaccess_Setenvif - Fatal编程技术网

Apache 当setenif被重写为index.php时,如何将其与Request_URI一起使用?

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

我们有一个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_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代码/代码>),因此在 /API/之前的空白还注意到:“代码> %{THI请求} /代码>将在内部重写的情况下保留初始请求的值。(这不是
%{REQUEST_URI}
的情况)