gpt4 book ai didi

c# - 具有 HTTP 主机条件的 IIS UrlRewrite RewriteMap

转载 作者:太空宇宙 更新时间:2023-11-03 13:37:23 26 4
gpt4 key购买 nike

我如何使用两个基于 HTTP-Host 的不同 RewriteMaps 来实现类似下面的东西?

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 响应。谁能指出我遗漏了什么?

最佳答案

@乔诺:是的。这是适用于条件和 {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>

关于c# - 具有 HTTP 主机条件的 IIS UrlRewrite RewriteMap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18235029/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com