0
votes

I need to rewrite rules for MVC app that created in IIS sub folder (www.example.com/test/App is application root)

Rewrite rules will redirect non-www request to www and http request to https

Cases:

A) Will be redirect to: 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

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.

Is there any rule or rules for achieve both A and B cases?

<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" />
1

1 Answers

0
votes

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