IIS 8.5 URL Rewrite for https and www for Subfolder MVC app



我需要重写在 IIS 子文件夹中创建的 MVC 应用程序的规则(www.example.com/test/App 是应用程序根目录)

重写规则会将非 www 请求重定向到 www,将 http 请求重定向到 https

例:

A) 将被重定向至:https://www.example.com/test/App/Controller

1) http://www.example.com/test/App/Controller
2) example.com/test/App/Controller
3) www.example.com/test/App/Controller

B) 将被重定向至:https://www.example.com/test/App

1) http://www.example.com/test/App
2) example.com/App
3) www.example.com/test/App

我在下面尝试了路由,但这些不是 A 部分下的重定向案例。

是否有任何规则或规则来实现A和B案例?

<rule name="Redirect to WWW" stopProcessing="true">
<match url=".*" />
<conditions>
    <add input="{HTTP_HOST}" pattern="^example.com$" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:0}" redirectType="Permanent" />
<rule name="Redirect to WWW https" stopProcessing="true">
<match url=".*" />
<conditions>
    <add input="{HTTPS}" pattern="^example.com$" />
</conditions>
<action type="Redirect" url="https://www.example.com/{R:0}" redirectType="Permanent" />

您可以通过两个规则来实现这一点:

<rule name="Redirect example.com to www" stopProcessing="true">
    <match url=".*" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="^example.com$" />
    </conditions>
    <action type="Redirect" url="https://www.example.com/{R:0}" />
</rule>
<rule name="Redirect to https" stopProcessing="true">
    <match url=".*" />
    <conditions>
        <add input="{HTTPS}" pattern="off" />
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" />
</rule>

您只需要将 example.com 替换为您的实际域名

最新更新