IIS URL forwarding: HTTP-HTTPS

I have an example.org site where I save subsites as example.com/project1 and example.com/project2 and so on. I need a simple HTTPβ†’HTTPS redirection only for some of the sub-sites, but I don’t need to write it in code files manually.

So, I found a URL-Rewrite2 and rules for it:

 <rewrite> <rules> <rule name="Redirect to HTTPS" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{HTTPS}" pattern="^OFF$" /> </conditions> <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" /> </rule> </rules> </rewrite> 

It works with no more than one problem: it redirects from http://example.com/project1 to https://example.com/ , so it lost part of the sub-site URL and any arguments.

How can this be fixed?

UPD: this rule is used

  <rule name="Redirect to HTTPS" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{HTTPS}" pattern="^OFF$" /> </conditions> <action type="Redirect" url="https://{HTTP_HOST}{UNENCODED_URL}" /> </rule> 

Subsite redirects normally, except that the arguments are duplicate. http://example.com/project1?page=2 turns into https://example.com/project1?page=2&page=2 . What am I doing wrong?

+5
source share
2 answers

Executed using this rule:

 <system.webServer> <rewrite> <rules> <rule name="Redirect to HTTPS" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{HTTPS}" pattern="^OFF$" /> </conditions> <action type="Redirect" url="https://{HTTP_HOST}{UNENCODED_URL}" appendQueryString="false" /> </rule> </rules> </rewrite> </system.webServer> 

Works well on sites.

+3
source
 <rewrite> <rules> <rule name="Redirect to http" enabled="true" patternSyntax="Wildcard" stopProcessing="true"> <match url="*" negate="false" /> <conditions logicalGrouping="MatchAny"> <add input="{HTTPS}" pattern="off" /> </conditions> <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Found" /> </rule> </rules> 

add this to the system.webserver section

0
source

Source: https://habr.com/ru/post/1238234/


All Articles