2

我正在使用 Isapi Rewrite 3(IIS 的 mod 重写克隆)并尝试根据查询字符串重写 URL - 然后在重写中传递该查询字符串的一部分。

因此,如果我输入这样的 URL:/test/home.cfm?page=default&arbitraryExtraArg=123

我希望将其重写为:/test/index.cfm?page=home&arbitraryExtraArg=123

我有以下条件/规则:

RewriteCond %{QUERY_STRING} ^page=default(.*)$ [I]
RewriteRule ^/test/home.cfm$ /test/index.cfm?page=home%1 [I,R=301]

但是永远不会传递额外的查询字符串变量。%1 似乎是空白的。

这就是如何从 RewriteCond 引用模式匹配,对吧?

我在这里想念什么?

谢谢!

编辑:在我看来,RewriteCond 完全被忽略了。这是我的日志文件的样子:

[snip] (2) init rewrite engine with requested uri /test/home.cfm?page=default
[snip] (1) Htaccess process request C:\Inetpub\wwwroot\dev\IsapiRewrite\httpd.conf
[snip] (3) applying pattern '^/test/home\.cfm$' to uri '/test/home.cfm'
[snip] (1) escaping /test/index.cfm?page=home 
[snip] (2) explicitly forcing redirect with http://www.devsite.com/test/index.cfm?page=home
[snip] (2) internal redirect with /test/home.cfm?page=default [INTERNAL REDIRECT]

[snip] (2) init rewrite engine with requested uri /test/index.cfm?page=home
[snip] (1) Htaccess process request C:\Inetpub\wwwroot\dev\IsapiRewrite\httpd.conf
[snip] (3) applying pattern '^/test/home\.cfm$' to uri '/test/index.cfm'

那里应该提到 RewriteCond 模式检查吗?

4

3 回答 3

3

但是永远不会传递额外的查询字符串变量。%1 似乎是空白的。

%1 是空白的,因为根据日志,您发出的请求是 /test/home.cfm?page=default - 没有第二个参数。

日志中没有 RewriteCond 处理可能是因为 RewriteLogLevel 低。

配置应该是:

RewriteCond %{QUERY_STRING} ^page=default(.+)$ [NC]

RewriteRule ^/test/home.cfm$ /test/index.cfm?page=home%1 [NC,R=301,L]

于 2009-07-09T14:46:41.557 回答
0

我认为 ISAPI Rewrite 与 mod_rewrite 有点不同:

每当您在复杂规则(带有条件的规则)中存在的任何正则表达式中放置括号时,您就是在标记可以在格式字符串(使用语法)中使用或在后续条件中$N作为反向引用(使用语法)的子匹配。\N这些子数学对于整个复杂规则是全局的(RewriteRule指令和相应的RewriteCond指令)。子匹配从对应于RewriteRule的第一个RewriteCond指令(如果存在这样的指令)开始从上到下和从左到右编号。

所以$1无论第一组出现在哪里,都尽量得到第一组的匹配:

RewriteCond %{QUERY_STRING} ^page=default(.*)$ [I]
RewriteRule ^/test/home\.cfm$ /test/index.cfm?page=home$1 [I,R=301]

ISAPI Rewrite 3似乎更兼容 Apache 的 mod_rewrite。

于 2009-07-07T14:28:11.457 回答
-1

我相信这也有效:

RewriteRule ^/test/home.cfm\?page=default(.*)$ /test/index.cfm?page=home%1 [I,R=301]
于 2009-07-07T14:35:25.127 回答