IIS重写模块和子应用程序 [英] IIS Rewrite Module and sub applications

查看:119
本文介绍了IIS重写模块和子应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的部署内容:

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

testRedirect is an empty website. All sub-applications are sub-folders that have been converted in application. All of them are ASP .Net MVC sites.

这是我想要设置的内容:

Here's what I want to setup:


  • Http:// localhost / 必须显示 SiteName1 的内容,而不是
    在地址栏中显示 Http:// localhost / SiteName1 / (必须
    逗留 Http:// localhost /

  • Http://localhost/ must show the content of SiteName1 without displaying Http://localhost/SiteName1/ in the adress bar (it must stay Http://localhost/)

Http:// localhost / SiteName1 / 必须显示<$的内容c $ c> SiteName1
在地址栏中没有显示 Http:// localhost / SiteName1 /
(必须逗留 Http:// localhost /

Http:// localhost / SiteName2 / 显示 SiteName2 的内容,
显示 Http:// localhost / SiteName2 / SiteName3 & SiteName4 的相同行为以及任何其他网站... 。)

Http://localhost/SiteName2/ shows the content of SiteName2 and displays Http://localhost/SiteName2/ in the adress bar (Same behavior for SiteName3 & SiteName4 and any other sites....)

换句话说,我想要我的 SiteName1 主页 网站

In other words, I want my SiteName1 to act like a home site

到目前为止我尝试过的内容类似于@cheesemacfly提供的答案此处

What I've tried so far, is something similar to the answer provided by @cheesemacfly here:

<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>

适用于Case1& 2但不是其他的。

It works great for Case1 & 2 but not the other ones.

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

I tried to add rules like this one, but it was not successful...

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


推荐答案

我认为你最好的选择就是触发重写只有当网址从您的某个子应用程序开始时,您已经拥有该规则。

I think your best option would be to trigger the rewrite rule you already have only when the url doesn't start with one of your sub-applications.

它将类似于:

<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>

我们在 SiteName1 / 时保留重定向请求(我们不需要更改),但只有当请求的URL不以 SiteName2 / 开头时才会触发重写规则SiteName3 / SiteName4 / (这就是 url =^(SiteName2 | SiteName3 | SiteName4)/表示我们使用 negate =true仅在模式匹配时才触发规则。

We keep the redirect when SiteName1/ is requested (we don't need to change this), but the rewrite rule is triggered only when the requested url doesn't start with SiteName2/ or SiteName3/ or SiteName4/ (that's what url="^(SiteName2|SiteName3|SiteName4)/" means and we use negate="true" to triggered the rule only when the pattern is not matched).

这篇关于IIS重写模块和子应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆