Click here to Skip to main content
15,887,988 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a website that has an SSL that I automatically remove the beginning www from when a user visits our site.

So when a user types in www.my-example.com they are redirected to https://my-example.com

Here is the rule I wrote to achieve this.

<rule name="Remove www.">
   <match url="(.*)" />
   <conditions>
     <add input="{HTTP_HOST}" pattern="^www.(.*)" />
   </conditions>
   <action type="Redirect" url="http://{C:1}/{URL}" />
 </rule>


This works fine in most cases but I'm running into an issue. We have many outside sources linking to individual pages we made like this: https://www.my-example.com/example-post

It correctly removes the www but appends a second / before the example post. So the above url would redirect to https://my-example.com//example-post

I need this to not happen. Any suggestions?

What I have tried:

I only have 2 rewrite rules in my web.config file. Here they are as is

<rule name="Force HTTPS Redirection" enabled="true" stopProcessing="true">
  <match url="^$" ignoreCase="false"/>
  <conditions>
    <add input="{HTTP_HOST}" pattern="localhost" negate="true" />
    <add input="{HTTPS}" pattern="^OFF$"/>
  </conditions>
  <action type="Redirect" url="https://{HTTP_HOST}/" redirectType="Permanent"/>
</rule>
<rule name="Remove www.">
  <match url="(.*)" />
  <conditions>
    <add input="{HTTP_HOST}" pattern="^www.(.*)" />
  </conditions>
  <action type="Redirect" url="http://{C:1}/{URL}" />
</rule>
Posted

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