RedirectMatch和查询string

比较这两个RedirectMatch的。 第一个不起作用:

RedirectMatch 302 ^/redirect\.php[?]page=(.+)$ http://somewhereelse.com/$1 

对此,将redirect到http://somewhereelse.com/?page=wherever :

 RedirectMatch 302 ^/redirect\.php([?]page=.+)?$ http://somewhereelse.com/$1 

RedirectMatch只匹配URI而不匹配查询string吗? Apache的文档在这方面有些模糊。 我想要做的是提取page查询参数,并redirect到使用它的另一个网站。

这是可能的RedirectMatch还是我必须使用RewriteCond + RewriteRule

在这种情况下不可能使用RedirectMatch ; 查询string不是与RewriteMatch进行比较的URLstring的一部分。

第二个例子工作,因为发送的客户端查询string被重新附加到目标URL – 所以可选的匹配什么也没有匹配, $1replace是一个空string,但客户端的原始查询string被卡住了。

将需要对%{QUERY_STRING}进行RewriteCond检查。

 RewriteCond %{QUERY_STRING} page=([^&]+) RewriteRule ^/redirect\.php$ http://somewhereelse.com/%1? [R=302,L] 

根据文档,它匹配URL:

提供的正则expression式与URLpath相匹配

http://httpd.apache.org/docs/current/mod/mod_alias.html#redirectmatch

每个URL由以下内容组成:scheme名称(通常称为协议),后跟一个冒号,两个斜杠,然后根据scheme,一个服务器名称(exp。ftp。,www。,smtp。等),然后是(。),然后是域名(或者IP地址),端口号,要获取的资源的path或要运行的程序,然后,对于诸如公共网关接口(CGI)脚本的程序,查询string和可选的片段标识符。

http://en.wikipedia.org/wiki/Uniform_Resource_Locator (节语法)

你可以用RewriteRule来做到这一点