Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IIS URL Rewrite https rule ignoring localhost

Tags:

iis

rewrite

I'm trying to write a URL rewrite rule to force a HTTPS connection. This should always happen except when a request is using localhost (e.g. http://localhost/mysite).

The rule is configured as following:

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

I also tried to use ^localhost and ^localhost/(.*) as a pattern for the URL condition with no help. Does anyone have an idea why this does not work and what a solution for this problem should be?

like image 372
One of many Avatar asked Oct 06 '14 15:10

One of many


Video Answer


1 Answers

Your code should look like this instead

<rule name="Redirect to https" enabled="true" stopProcessing="true">    <match url="(.*)" />    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">       <add input="{HTTPS}" pattern="off" />       <add input="{HTTP_HOST}" pattern="localhost" negate="true" />    </conditions>    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" /> </rule> 
like image 58
Justin Iurman Avatar answered Sep 22 '22 09:09

Justin Iurman