【发布时间】:2013-08-16 14:24:16
【问题描述】:
如何使用基于 HTTP-Host 的两个不同的 RewriteMap 来实现类似以下的功能?
www.myfoo.com/test 应重写为 /foo/test.aspx
并且
www.mybar.com/test 应重写为 /bar/test.aspx
到目前为止,我已经找到了 http://forums.iis.net/t/1177509.aspx/1 并根据我的需要对其进行了调整:
<rule name="Rewrite rule1 for rewritemapFoo">
<match url=".*"/>
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.myfoo\.com$" />
<add input="{URL}" matchType="Pattern" pattern="^.+\.((axd)|(js)|(xaml))$" ignoreCase="true" negate="true"/>
<add input="{rewritemapFoo:{REQUEST_URI}}" pattern="(.+)"/>
</conditions>
<action type="Rewrite" url="{C:1}" appendQueryString="false"/>
</rule>
<rule name="Rewrite rule1 for rewritemapBar">
<match url=".*"/>
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.mybar\.com$" />
<add input="{URL}" matchType="Pattern" pattern="^.+\.((axd)|(js)|(xaml))$" ignoreCase="true" negate="true"/>
<add input="{rewritemapBar:{REQUEST_URI}}" pattern="(.+)"/>
</conditions>
<action type="Rewrite" url="{C:1}" appendQueryString="false"/>
</rule>
...
<rewriteMap name="rewritemapFoo">
<add key="/test" value="/foo/test.aspx"/>
</rewriteMap>
<rewriteMap name="rewritemapBar">
<add key="/test" value="/bar/test.aspx"/>
</rewriteMap>
不幸的是,我在调用 www.myfoo.com/test 和 www.mybar.com/test 时只会收到 404 响应。谁能指出,我错过了什么?
【问题讨论】:
-
你真的需要 RewriteMap 吗?您可以简单地重用 HTTP_HOST 中的任何内容
-
嘿@citronas,我也有同样的问题,想知道你是否找到了解决方案?
-
@Jono:我将代码发布到新答案中
标签: c# asp.net iis url-rewriting iis-7.5