Forcing SSL and non-WWW

38 views
Skip to first unread message

Paul Giesenhagen

unread,
Jul 6, 2020, 11:13:48 AM7/6/20
to CFWheels
I am trying to force SSL and non-WWW urls but with the following web.config rules I get this issue:

when someone goes to www.whatever.com it writes it to https://whategver.com//rewrite.cfm  

Now if it use http://www.whatever.com/somepage-here  it will do everything correctly .. it's just the homepage that messes up. 


Here is my web.config - anyone see anything I have messed up?


<rule name="Force non-WWW" enabled="true" stopProcessing="true">
 <match url="(.*)" />
 <conditions logicalGrouping="MatchAny">
 <add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" />
 </conditions>
 <action type="Redirect" url="https://{C:2}/{R:1}" appendQueryString="true" />
</rule>

<rule name="HTTP to HTTPS redirect" stopProcessing="true"> 
   <match url="(.*)" /> 
   <conditions> 
   <add input="{HTTPS}" pattern="off" ignoreCase="true" />
   </conditions> 
   <action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" />
</rule> 

Paul Giesenhagen

unread,
Jul 7, 2020, 9:15:45 AM7/7/20
to CFWheels
Sadly this was fairly simple to fix up ... I needed to put the following BEFORE the Coldfusion on Wheels URL Rewriting script.

<rule name="HTTPSCanonicalHostNameRule" enabled="true" stopProcessing="true">
            <match url="(.*)" />
            <conditions logicalGrouping="MatchAny">
                <add input="{HTTP_HOST}" pattern="^hwy38arena\.com$" negate="true" />
                <add input="{HTTPS}" pattern="off" />
            </conditions>
            <action type="Redirect" url="https://hwy38arena.com/{R:1}" appendQueryString="true" />
</rule>
<rule name="ColdFusion on Wheels URL Rewriting" enabled="true">
<match url="^(.*)$" ignoreCase="true" />
<conditions logicalGrouping="MatchAll">
<add input="{SCRIPT_NAME}" negate="true" pattern="^/(flex2gateway|media|jrunscripts|cf_scripts|cfide|CFFileServlet|cfformgateway|lucee|files|images|javascripts|miscellaneous|stylesheets|wheels/public/assets|robots.txt|favicon.ico|sitemap.xml|rewrite.cfm)($|/.*$)" />
</conditions>
<action type="Rewrite" url="/rewrite.cfm/{R:1}" />
</rule>
Reply all
Reply to author
Forward
0 new messages