Phi*_* P. 10 asp.net iis iis-7 url-rewriting
我有一个ReWrite Map,我想将请求的URL中的任何查询参数附加到重写的URL.
例如:
我的web.config是:
[...]
<rules>
<clear />
<rule name="Rewrite rule1 for SiteMapEngine">
<match url=".*" />
<conditions>
<add input="{SiteMapEngine:{REQUEST_URI}}" pattern="(.+)" />
</conditions>
<action type="Rewrite" url="{C:1}" appendQueryString="true" />
</rule>
</rules>
[...]
Run Code Online (Sandbox Code Playgroud)
Dun*_*unc 25
简短回答:
使用PATH_INFO服务器变量而不是REQUEST_URI,因为您不希望在匹配中包含查询字符串.
完整说明:
这引起了我的注意 - 基本上它是在IIS URL重写模块中使用重写映射的一个微妙之处.
在您的情况下,SiteMapEngine将是URL的静态键值列表:
<rewrite>
<rewriteMaps>
<rewriteMap name="SiteMapEngine" defaultValue="">
<add key="/page/abc/" value="/index.cfm?page=abc" />
...
</rewriteMap>
</rewriteMaps>
...
</rewrite>
Run Code Online (Sandbox Code Playgroud)
规则中的{SiteMapEngine:{REQUEST_URI}}条件检查此重写映射中是否存在与REQUEST_URI服务器变量匹配的键:
{REQUEST_URI} = /page/abc/?param1=111
Run Code Online (Sandbox Code Playgroud)
请注意,此变量包含查询字符串 - 因此无法找到匹配的键.
而是使用PATH_INFO服务器变量,它等同于REQUEST_URI但没有查询字符串:
{PATH_INFO} = /page/abc/
Run Code Online (Sandbox Code Playgroud)
所以正确的规则是:
<rule name="Rewrite rule1 for SiteMapEngine">
<match url=".*" />
<conditions>
<add input="{SiteMapEngine:{PATH_INFO}}" pattern="(.+)" />
</conditions>
<action type="Rewrite" url="{C:1}" />
</rule>
Run Code Online (Sandbox Code Playgroud)
小智 12
如果我能找到这方面的参考,我会被诅咒,但我的理解是,在某些版本的IIS {REQUEST_URI}中没有它的查询字符串,如果启用了重写,它将完全为空.
您应该能够使用{PATH_INFO}.
这个错误报告(针对Drupal!)是你正在描述的问题,我想:http://drupal.org/node/298016
有一个来自Microsoft的修补程序,但我还没有尝试过:http://support.microsoft.com/kb/954946
这是我的规则。它似乎按预期工作:
<rule name="Insert index.cfm" enabled="true" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.cfm/{PATH_INFO}" appendQueryString="true" />
</rule>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17494 次 |
| 最近记录: |