繁体   English   中英

IIS 8.5 URL重写,用于子文件夹MVC应用程序的https和www

[英]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 : 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 : 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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM