Answered by:
How to rewrite url with HTTP or HTTPS

Question
-
User-5842959 posted
I have the following rule in my web.config file. As you can see it takes all subdomains and redirects to 'www.'
I also have an HTTP module that does switching between HTTP and HTTPS on the OnPreRequestHandlerExecute event. From what I have read and understood, this occurs after the rewrite but I could be wrong.
This code actually works in Firefox, transferring to www. then HTTPS where necessary, however it doesn't work in either Chrome or IE, maintaining the HTTP scheme.
I would like to make some changes to the code below so that the scheme is carried over rather than just assume HTTP which is does at the moment.
<rewrite xdt:Transform="Insert"> <rules> <rule name="Redirect to www"> <match url="(.*)" /> <conditions> <add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" negate="true" /> </conditions> <action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" redirectType="Permanent" /> </rule> </rules> </rewrite>
Friday, September 6, 2013 7:13 AM
Answers
-
User-619846739 posted
Here's a blog post on how to do that:
http://weblogs.asp.net/owscott/archive/2012/11/07/url-rewrite-protocol-http-https-in-the-action.aspx
To achieve this with your rule, it can be updated to the following:
<rule name="Redirect to www" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" negate="true" /> <add input="{CACHE_URL}" pattern="^(.+)://" /> </conditions> <action type="Redirect" url="{C:1}://www.{HTTP_HOST}/{R:0}" redirectType="Permanent" /> </rule>
- Marked as answer by Anonymous Tuesday, September 28, 2021 12:00 AM
Monday, September 9, 2013 12:03 PM
All replies
-
User-5842959 posted
No-one got any ideas as to how to resolve this on IIS forum?
Monday, September 9, 2013 4:54 AM -
User-619846739 posted
Here's a blog post on how to do that:
http://weblogs.asp.net/owscott/archive/2012/11/07/url-rewrite-protocol-http-https-in-the-action.aspx
To achieve this with your rule, it can be updated to the following:
<rule name="Redirect to www" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" negate="true" /> <add input="{CACHE_URL}" pattern="^(.+)://" /> </conditions> <action type="Redirect" url="{C:1}://www.{HTTP_HOST}/{R:0}" redirectType="Permanent" /> </rule>
- Marked as answer by Anonymous Tuesday, September 28, 2021 12:00 AM
Monday, September 9, 2013 12:03 PM -
User-5842959 posted
Thanks.
Monday, October 14, 2013 10:54 AM