如何在Apache http mod_rewrite中使用原子作为路径变量?

如何在Apache http mod_rewrite中使用原子作为路径变量?,apache,http,redirect,mod-rewrite,Apache,Http,Redirect,Mod Rewrite,如何使用源URL中的路径变量使用apache mod_rewrite重定向?简言之 这很有效 RewriteRule ^/?sourceURL/path/var1/(.*)$ http://destination/path?var1=$1 [L] 但事实并非如此 RewriteRule ^/?sourceURL/path/?var1=(.*)$ http://destination/path?var1=$1 [L] 上下文 服务器版本:Apache/2.4.6(CentOS)这是因为您无法以

如何使用源URL中的路径变量使用apache mod_rewrite重定向?简言之

这很有效

RewriteRule ^/?sourceURL/path/var1/(.*)$ http://destination/path?var1=$1 [L]
但事实并非如此

RewriteRule ^/?sourceURL/path/?var1=(.*)$ http://destination/path?var1=$1 [L]
上下文


服务器版本:Apache/2.4.6(CentOS)

这是因为您无法以重写规则的模式匹配url
QueryString
。您需要使用
RewriteCond
指令

RewriteCond %{QUERY_STRING} ^var1=(.*)$ [NC]
RewriteRule ^/?sourceURL/path/?$ http://destination/path?var1=%1 [L,R]