[英]IIS UrlRewrite RewriteMap with HTTP Host condition
How can I use two different RewriteMaps based on the HTTP-Host to achieve something like the following? 如何使用基于HTTP主机的两个不同的RewriteMaps来实现如下所示的功能?
www.myfoo.com/test should be rewritten to /foo/test.aspx www.myfoo.com/test应该重写为/foo/test.aspx
and 和
www.mybar.com/test should be rewritten to /bar/test.aspx www.mybar.com/test应该重写为/bar/test.aspx
So far I've found http://forums.iis.net/t/1177509.aspx/1 and adapted it to my needs: 到目前为止,我已经找到了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>
Unfortunately, I'll only get a 404 response upon calling www.myfoo.com/test and www.mybar.com/test. 不幸的是,我在致电www.myfoo.com/test和www.mybar.com/test时只会收到404响应。 Can anyone point out, what I'm missing?
谁能指出我所缺少的吗?
@Jono: Yes. @Jono:是的。 This is the code thats work with conditions and
{HTTP_HOST}
这是适用于条件和
{HTTP_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>
You can use Conditions for this. 您可以为此使用条件 。 In conditions you have access to server variables which contains a key 'HTTP_HOST' with the value for host name.
在某些情况下,您可以访问服务器变量 ,该服务器变量包含键“ HTTP_HOST”以及主机名的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.