Programming Newbie February 2016

HTTPS redirect on sub application

I have an application with this domain http://abc.example.com/portal. Portal is a sub application to the main application (abc.example.com) on IIS.

I would like to redirect to https://abc.example.com/portal if anyone access it by http://abc.example.com/portal.

I added these lines to the web.config:

<rewrite>
   <rules>
       <rule name="HTTPS Redirect" enabled="true">
           <match url="(.*)" ignoreCase="false" />
           <conditions>
               <add input="{HTTPS}" pattern="off" />
           </conditions>
           <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
       </rule>
    </rules>
</rewrite>

After this, if I call site http://abc.example.com/portal, it takes me to https://abc.example.com/ and not to https://abc.example.com/portal.

Do you guys have any idea how can I make this work?

Thanks,

Answers


Josh February 2016

Try changing your rule to:

<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}/{R:1}" />

Also, if the /example subdirectory is an application, make sure these rewrite rules are placed in that web.config and not the parent application's web.config.

Post Status

Asked in February 2016
Viewed 3,256 times
Voted 13
Answered 1 times

Search




Leave an answer