I have access to IIS application and I do not know who created and deployed it. But I need to make this app work through https protocol. I've created let's encrypt certificate and applied it to the site. If I follow some URL like: https://example.com/aboutus
and so on - it works as expected. But when I try to access https://example.com
, it forcibly redirects me to http://example.com
. Then, when I access other pages through navigation menu, they are http://example.com/about_us
and so on, except a few pages which are forcibly redirected to https
, such as https://example.com/sign_up
and sign_in
.
If I apply the following rule:
<rule name="Redirect to HTTPS" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" />
</rule>
all pages are being redirected, but the main page could not be loaded because of hard-coded redirect:
I don't know if it hard-coded somewhere or no. But at the moment I want to redirect everything except the main page to https. How could I do it?
Answer here does not work in my case
This does not work also:
<rule name="Redirect to HTTPS" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="^OFF$" />
<add input="{URL}" pattern="example\.com\/.+" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" logRewrittenUrl="true" />
</rule>
By following Lex Li's advice about using FRT, I've found out URL Rewrite module works with relative paths. For example, http://example.com/about_us
was just /about_us
and because of this my pattern="example\.com\/.+"
did not work.
The following rule works as expected:
<rule name="Redirect to HTTPS" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{URL}" pattern="\/.+" />
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
</rule>
All pages with http
protocol which relative pates start with /
and have at least one symbol behind it, should be redirected.