[英]IIS 8.5 URL Rewrite for https and www for Subfolder MVC app
I need to rewrite rules for MVC app that created in IIS sub folder (www.example.com/test/App is application root) 我需要为在IIS子文件夹中创建的MVC应用程序重写规则(www.example.com/test/App是应用程序根目录)
Rewrite rules will redirect non-www request to www and http request to https 重写规则会将非www请求重定向到www,将http请求重定向到https
Cases: 案例:
A) Will be redirect to: https://www.example.com/test/App/Controller
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) Will be redirect to: https://www.example.com/test/App
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
I tried routings below, but these are not redirects cases under A section. 我在下面尝试了路由,但这些不是A部分下的重定向案例。
Is there any rule or rules for achieve both A and B cases? 是否有同时实现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" />
You can achieve that with two rules: 您可以通过两个规则来实现:
<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>
You just need to replace example.com with your actual domain name 您只需要用您的实际域名替换example.com
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.