C# 具有HTTP主机条件的IIS URL重写重写映射
如何使用基于HTTP主机的两个不同的重写映射来实现以下内容 www.myfoo.com/test应重写为/foo/test.aspxC# 具有HTTP主机条件的IIS URL重写重写映射,c#,asp.net,iis,url-rewriting,iis-7.5,C#,Asp.net,Iis,Url Rewriting,Iis 7.5,如何使用基于HTTP主机的两个不同的重写映射来实现以下内容 www.myfoo.com/test应重写为/foo/test.aspx 和 www.mybar.com/test应重写为/bar/test.aspx 到目前为止,我已经找到并调整了它以满足我的需要: <rule name="Rewrite rule1 for rewritemapFoo"> <match url=".*"/> <conditions> <add input="{HTT
和
www.mybar.com/test应重写为/bar/test.aspx 到目前为止,我已经找到并调整了它以满足我的需要:
<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响应。有人能指出我缺少什么吗?你可以用这个。在您有权访问的条件下,其中包含一个键“HTTP\u HOST”,该键的值为主机名。@Jono:Yes。这是使用条件和
{HTTP\u HOST}
<rule name="Rewrite rule1 for ABC">
<match url=".*"/>
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.abc\.de$"/>
<add input="{URL}" matchType="Pattern" pattern="^.+\.((axd)|(js)|(xaml))$" ignoreCase="true" negate="true"/>
<add input="{ABC:{REQUEST_URI}}" pattern="(.+)"/>
</conditions>
<action type="Rewrite" url="{C:1}" appendQueryString="false"/>
</rule>
<rule name="Rewrite rule2 for ABC">
<match url=".*"/>
<conditions>
<add input="{HTTP_HOST}" pattern="^abc\.de$"/>
<add input="{URL}" matchType="Pattern" pattern="^.+\.((axd)|(js)|(xaml))$" ignoreCase="true" negate="true"/>
<add input="{ABC:{REQUEST_URI}}" pattern="(.+)"/>
</conditions>
<action type="Rewrite" url="{C:1}" appendQueryString="false"/>
</rule>
<rule name="Rewrite rule1 for XYZ">
<match url=".*"/>
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.xyz\.de$"/>
<add input="{URL}" matchType="Pattern" pattern="^.+\.((axd)|(js)|(xaml))$" ignoreCase="true" negate="true"/>
<add input="{XYZ:{REQUEST_URI}}" pattern="(.+)"/>
</conditions>
<action type="Rewrite" url="{C:1}" appendQueryString="false"/>
</rule>
<rule name="Rewrite rule2 for XYZ">
<match url=".*"/>
<conditions>
<add input="{HTTP_HOST}" pattern="^xyz\.de$"/>
<add input="{URL}" matchType="Pattern" pattern="^.+\.((axd)|(js)|(xaml))$" ignoreCase="true" negate="true"/>
<add input="{XYZ:{REQUEST_URI}}" pattern="(.+)"/>
</conditions>
<action type="Rewrite" url="{C:1}" appendQueryString="false"/>
</rule>
<rewriteMap name="ABC">
<add key="/" value="/aa/start.aspx"/>
<add key="/foo" value="/aa/foo.aspx"/>
</rewriteMap>
<rewriteMap name="XYZ">
<add key="/" value="/bb/start.aspx"/>
<add key="/foo" value="/bb/foo.aspx"/>
</rewriteMap>
这正是我正在尝试的。你介意告诉我,我在我的情况下做错了什么吗?@citronas为什么在两条规则的主机条件末尾都有-->呢?对不起,匿名问题。我的代码中没有它们,因此对其进行了相应的编辑。@citronas try ignoreCase=“true”用于主机条件,并且主机名可能被转换为全大写。此外,您正在使用映射,因此我假设您在映射中为传入url定义了相应的键。ignoreCase=“true”不成功。映射也是代码示例的一部分。您真的需要重写映射吗?你可以简单地重用HTTP_HOSTHey@citronas中的任何内容,我有完全相同的问题,不知道你是否找到了解决方案?@Jono:我将我的代码发布到了一个新的回复中谢谢@citronas!