nat*_*ate 6 mod-rewrite redirect mod-alias querystring apache-2.2
比较这两个RedirectMatch。第一个不起作用:
RedirectMatch 302 ^/redirect\.php[?]page=(.+)$ http://somewhereelse.com/$1
Run Code Online (Sandbox Code Playgroud)
与此相反,它将重定向到http://somewhereelse.com/?page=wherever:
RedirectMatch 302 ^/redirect\.php([?]page=.+)?$ http://somewhereelse.com/$1
Run Code Online (Sandbox Code Playgroud)
是否RedirectMatch只匹配 URI 而不是查询字符串?Apache 的文档在这方面有点含糊。我想要做的是提取page查询参数并使用它重定向到另一个站点。
这是可能的RedirectMatch还是我必须使用RewriteCond+ RewriteRule?
Sha*_*den 10
RedirectMatch不幸的是,在这种情况下无法使用;查询字符串不是与之比较的 URL 字符串的一部分RewriteMatch。
第二个示例有效,因为客户端发送的查询字符串被重新附加到目标 URL - 因此可选匹配不匹配,$1替换为空字符串,但随后客户端的原始查询字符串被卡住。
一RewriteCond对检查%{QUERY_STRING}将代替需要。
RewriteCond %{QUERY_STRING} page=([^&]+)
RewriteRule ^/redirect\.php$ http://somewhereelse.com/%1? [R=302,L]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10040 次 |
| 最近记录: |