Apache mod_rewrite[E]重定向前缀带有RewriteCond

Apache mod_rewrite[E]重定向前缀带有RewriteCond,apache,mod-rewrite,Apache,Mod Rewrite,在Apache服务器中,如果特定URL匹配,我需要禁用keepalive。 为此,我使用mod_rewrite来设置它,然后让脚本运行它的进程 RewriteCond %{REQUEST_URI} ^/specific_url RewriteRule ^ - [E=nokeepalive] ....... RewriteCond %{REQUEST_FILENAME} -f RewriteRule ^ - [L] 现在我的问题是nokeepalive如果与匹配,就会被前缀/重命名为with

在Apache服务器中,如果特定URL匹配,我需要禁用keepalive。
为此,我使用mod_rewrite来设置它,然后让脚本运行它的进程

RewriteCond %{REQUEST_URI} ^/specific_url
RewriteRule  ^ - [E=nokeepalive]
.......
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
现在我的问题是
nokeepalive
如果与
匹配,就会被前缀/重命名为with REDIRECT 从这个问题:
我认为这是由于
重写规则

但是如果我删除RewriteCond,它的前缀就不是(这将禁用
keepAlive
globaly和任何URL)
有没有办法防止使用RewriteCond作为前缀?
我不能使用
setenif
,因为我使用
mod_rewrite
,所以我必须使用
RewriteRule

SetEnv/SetEnviF也无法工作,因为它们无法读取未使用SetEnv/SetEnviF赋值的变量。 我尝试使用SetEnvIf仅在存在重定向_nokeepalive时进行定义(因为nokeepalive只需要定义,而不管值是多少),但没有效果

我不能使用setenif,因为我使用mod_rewrite,所以我必须使用RewriteRule

您可以将mod_setenif与
一起使用

编辑: 请记住在
SetEnv
之前添加
PassEnv REDIRECT\u nokeepalive
,因为
SetEnv
无法从mod_rewrite读取环境变量

我只想指出: 此处有两个空格,这可能会导致其他重写规则出现问题:


第一次设置后,我使用了第二种方法。这很难看,但它可以工作,而且我现在找不到其他解决Apache行为的方法。SetEnv nokeepalive${REDIRECT_nokeepalive}无法工作,因为SetEnv无法读取未使用SetEnv或setenif分配的变量。我尝试使用SetEnvIf仅在REDIRECT_nokeepalive存在时进行定义(因为nokeepalive只需要定义,而不考虑其值),但没有效果。@R.Damasinoro您可以在之前使用
PassEnv REDIRECT_nokeepalive
SetEnv@R.Damasinoro,您可能还需要将
${REDIRECT\u nokeepalive}
更改为
%{REDIRECT_nokeepalive}e
<If "%{REQUEST_URI} =~ /regextomatchurl/">
# or use <If "%{REQUEST_URI} == 'urlstring'">
SetEnv nokeepalive 1
</If>
SetEnv nokeepalive ${REDIRECT_nokeepalive}
RewriteRule  ^ - [E=nokeepalive]
           ^^