Click here to Skip to main content
15,867,771 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a small question where my search fu has left me without an answer.

Example situation
I'm owner of the domains "example.org" and "www.example.org"
I want to redirect "example.org" to "www.example.org"
There already exists a website in IIS 8 that handles both domains

What I did?
1. Create an empty folder for a new "website" in IIS 8 called "example.org"
2. Create a new website in IIS 8 with hostname "example.org"
3. Adding a https binding to this new website
4. Configuring the "HTTP Redirect" as follows:
For "Redirect request to this destination" I set the value "www.example.org"
The redirect behaviour is configured to keep the relative path and query intact and to include redirects to subdirecties (there aren't any anyways) and to use a permanent redirect.

What doesn't work?
The redirection works perfectly fine except a small detail: The protocol used for the inbound requests gets dropped.

That means:
Requests to https://example.org are redirected to http://www.example.org

We have basically the following scenario:
http --> http
https --> http


My actual question
Is it possible to configure the HTTP redirection to keep the inbound protocol? From my view this should be something so trivial and easy that I don't understand why this doesn't work
http --> http
https --> https


What I tried so far
Google wasn't helpfull at all I found tons of search results about how I can redirect http to https. But that really isn't what I want.

I tried to configure to redirect the requests from "www.example.org" to "https://www.example.org" (See the Step 4 of "What I did?") but then I have opposite of what I had before (everything goes to https)
http --> https
https --> https


I found a similiar question on SO concerning url rewriting here[^] but url rewriting isn't really what I try or want.


I already thank you for your assistance ;)


TL;DR
IIS 8, HTTP Redirection, keep protocol (http/https), no helpful search results (so far)
Posted
Updated 18-Mar-16 2:15am

1 solution

Hi You have to install URL rewrite module for IIS and then use following:

XML
<rewrite>
<system.webserver>
     <rules>
       <rule name="http to https" enabled="false" stopprocessing="true">
         <match url="(.*)" />
         <conditions>
           <add input="{HTTPS}" pattern="^OFF$" />
         </conditions>
         <action type="Redirect" url="https://{HTTP_HOST}/ISOS.EHP.API/" redirecttype="SeeOther" />
       </rule>
     </rules>
   
</system.webserver>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900