IIS重写模块和子应用程序

Max*_*xSC 5 iis url rewrite url-rewriting url-rewrite-module

这是我部署的内容:

IIS部署

testRedirect是一个空的网站.所有子应用程序都是已在应用程序中转换的子文件夹.所有这些都是ASP .Net MVC网站.

这是我想要设置的内容:

  • Http://localhost/必须显示内容SiteName1而不Http://localhost/SiteName1/在地址栏中显示(必须保留Http://localhost/)

  • Http://localhost/SiteName1/必须显示内容SiteName1 而不Http://localhost/SiteName1/在地址栏中显示(必须保留Http://localhost/)

  • Http://localhost/SiteName2/显示地址栏中的内容SiteName2和显示Http://localhost/SiteName2/(SiteName3和&SiteName4和任何其他网站的相同行为......)

换句话说,我希望我SiteName1的行为像一个家庭网站

到目前为止我尝试过的是类似@cheesemacfly 在这里提供的答案:

<rules>
    <rule name="Redirect if SiteName1" stopProcessing="true">
        <match url="^SiteName1/(.*)$" />
        <action type="Redirect" url="{R:1}" />
    </rule>
    <rule name="Rewrite to sub folder">
        <match url="^.*$" />
        <action type="Rewrite" url="SiteName1/{R:0}" />
    </rule>
</rules>
Run Code Online (Sandbox Code Playgroud)

它适用于Case1和2,但不适用于其他.

我试图添加像这样的规则,但它没有成功......

<rule name="if_not_SiteName1" stopProcessing="true">
   <match url="^SiteName1/(.*)$" negate="true" />
   <action type="None" />
</rule>
Run Code Online (Sandbox Code Playgroud)

che*_*fly 4

我认为您最好的选择是仅当网址不以您的子应用程序之一开头时才触发您已有的重写规则。

它会是这样的:

<rules>
    <rule name="Redirect if SiteName1" stopProcessing="true">
        <match url="^SiteName1/(.*)$" />
        <action type="Redirect" url="{R:1}" />
    </rule>
    <rule name="Rewrite to sub folder">
        <match url="^(SiteName2|SiteName3|SiteName4)/" negate="true" />
        <action type="Rewrite" url="SiteName1/{R:0}" />
    </rule>
</rules>
Run Code Online (Sandbox Code Playgroud)

我们在请求时保留重定向SiteName1/(我们不需要更改它),但仅当请求的 url 不以 or 开头时才会触发重写规则SiteName2/(这就是意思,我们仅在以下情况下才触发规则SiteName3/)模式匹配)。SiteName4/url="^(SiteName2|SiteName3|SiteName4)/"negate="true"