Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rewriting URLs from https:// to http:// in IIS7

I'm trying to rewrite urls from the form:

https://example.com/about 

to the form

http://example.com/about 

using IIS7 URL rewriting:

<!-- http:// to https:// rule --> <rule name="ForceHttpsBilling" stopProcessing="true">   <match url="(.*)billing/(.*)" ignoreCase="true" />   <conditions>     <add input="{HTTPS}" pattern="off" ignoreCase="false" />   </conditions>   <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}{REQUEST_URI}" /> </rule>  <!-- https:// to http:// rule -->     <rule name="ForceNonHttps" stopProcessing="true">   <match url="(.*)billing/(.*)" ignoreCase="true" negate="true" />   <conditions>       <add input="{SERVER_PORT}" pattern="^443$" />   </conditions>   <action type="Redirect" redirectType="Found" url="http://{HTTP_HOST}{REQUEST_URI}" /> </rule> 

I'm at a loss; I've been browsing the web for examples and trying every syntax I can think of. The rewrite rules I specify simply don't appear to work at all for any https requests, as if all the https:// requests are flat out invisible to the rewrite engine.

rules work fine; see answer below.

like image 290
Jeff Atwood Avatar asked Oct 08 '09 07:10

Jeff Atwood


People also ask

Where is URL Rewrite in IIS?

1. First, open your IIS Manager and click on Default Web Site at the left panel. Double-click on the URL Rewrite module, as shown below, to add rewrite rules.


2 Answers

Turns out that I had port :443 bound to a different website!

The above rewrite rules work fine for http:// to https:// rewriting and vice-versa -- though there might be more optimal or simple ways to do it.

Leaving this question here for future voyagers to find, as I didn't see many good examples of the https:// to http:// rewriting scenario on the web.

like image 140
Jeff Atwood Avatar answered Oct 05 '22 16:10

Jeff Atwood


This post is a little old, but I wanted to answer. I am using ASP.Net MVC3, and Fabio's answer above didn't work for me. The easiest solution I came up with to handle the https redirect to http, while still allowing valid https pages to request secure content was just to add Whitelist rules above my https/http redirects:

    <rule name="WhiteList - content folder" stopProcessing="true">       <match url="^content/"/>       <conditions logicalGrouping="MatchAll" trackAllCaptures="false"/>       <action type="None"/>     </rule>     <rule name="Redirect to HTTPS" stopProcessing="true">       <match url="(.*)billing/(.*)" ignoreCase="true" />       <conditions>         <add input="{HTTPS}" pattern="^OFF$" />       </conditions>       <action type="Redirect" url="https://{HTTP_HOST}/billing/" redirectType="SeeOther" />     </rule>     <rule name="ForceNonHttps" stopProcessing="true">       <match url="(.*)billing/(.*)" ignoreCase="true" negate="true" />       <conditions>         <add input="{SERVER_PORT}" pattern="^443$" />       </conditions>       <action type="Redirect" redirectType="Found" url="http://{HTTP_HOST}{REQUEST_URI}" />     </rule> 
like image 21
Ben Avatar answered Oct 05 '22 15:10

Ben