ISAPI重写 - 访问查询字符串模式的匹配重写规则
-
11-09-2019 - |
题
我使用ISAPI重写3(国防部重写克隆为IIS),并试图重写基于查询串的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模式检查的提及在那里?
解决方案
但额外的查询字符串变量从未通过。 %1似乎是空白的。
%1是空的,因为根据日志你做出该请求是/test/home.cfm?page=default - 无第二个参数
的RewriteCond处理的日志中由于缺少可能是由于低RewriteLogLevel。
和的配置应该是:
的RewriteCond%{QUERY_STRING} ^页=缺省(+)$ [NC]
重写规则^ /测试/ home.cfm $ /test/index.cfm?page=home%1 [NC,R = 301,L]
其他提示
我认为ISAPI重写是有点不同的,以mod_rewrite的:
每当你把括号中的任何正则表达式存在于复杂的规则(用条件的规则)您已(利用
$N
语法)或作为反向引用(使用\N
语法标记,可以在格式字符串中使用的子匹配)在随后的条件下。这些submathces是全球对整个复杂的规则(重写规则指令和对应的的RewriteCond 指令)。子匹配被从上向下编号并从左至右从第一开始的RewriteCond 指令(如果这样的指令存在)相应于重写规则
所以尽量$1
获得第一组的比赛,无论它出现:
RewriteCond %{QUERY_STRING} ^page=default(.*)$ [I]
RewriteRule ^/test/home\.cfm$ /test/index.cfm?page=home$1 [I,R=301]
ISAPI重写3 似乎是Apache的mod_rewrite更相容。
我相信这个作品也:
RewriteRule ^/test/home.cfm\?page=default(.*)$ /test/index.cfm?page=home%1 [I,R=301]