我正在使用Isapi Rewrite 3(IIS的mod重写克隆)并尝试根据查询字符串重写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模式检查?
3 回答
%1为空白,因为根据日志,您提出的请求是/test/home.cfm?page=default - 没有第二个参数 .
日志中缺少RewriteCond处理可能是由于RewriteLogLevel较低 .
配置应该是:
RewriteCond% ^ page = default( . )$ [NC]
RewriteRule ^ / test / home.cfm $ /test/index.cfm?page=home%1 [NC,R = 301,L]
我认为ISAPI Rewrite与mod_rewrite有点不同:
所以尝试
$1
以获得第一组的匹配,无论它出现在何处:ISAPI Rewrite 3似乎与Apache的mod_rewrite更兼容 .
我相信这也有效: