[英]IIS Rewrite Module and sub applications
这是我部署的内容:
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>
它适用于Case1和2,但不适用于其他。
我试图添加像这样的规则,但它没有成功......
<rule name="if_not_SiteName1" stopProcessing="true">
<match url="^SiteName1/(.*)$" negate="true" />
<action type="None" />
</rule>
我认为你最好的选择是触发你已经拥有的重写规则,只有当url 不是从你的一个子应用程序开始时。
它会是这样的:
<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"
仅在模式不匹配时触发规则)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.