Tony
Tony

Reputation: 12695

IIS redirect to HTTPS changes the URL

Ii'm trying to force HTTPS redirection in IIS, based on the article

https://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-configuration-reference#Accessing_URL_Parts_from_a_Rewrite_Rule

what's strange, when I create the Redirect URL as follows

https://{HTTP_HOST}/{REQUEST_URI}

and I open http://some.com/somePage, instead of being redirected to https://some.com/somePage I'm redirected to https://some.com/h

what's that 'h' letter at the end and why 'somePage' is missing ?

Upvotes: 0

Views: 351

Answers (1)

Vlado Pandžić
Vlado Pandžić

Reputation: 5048

This is the code that redirects every http link to it's https version. If you put it in the web config it should work:

<rule name="Redirect to www MAIN"  stopProcessing="true">
 <match url=".*" />
<conditions logicalGrouping="MatchAny">
  <add input="{HTTP_HOST}" pattern="^yourdomain.com$" />
  <add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect"  url="https://www.yourdomain.com/{R:0}" redirectType="Permanent" />
 </rule>

Upvotes: 1

Related Questions