URL Rewrite Rule to https and non-www

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
9 years ago
Hello guys,

well, im having an issue with URL Rewrite module, and I wonder if anyone has been able to actually do it.  The requirement is to ALWAYS redirect to https://domain.com  and It seems to be easy but maybe the way nopCommerce works prevents it from working... :(

Example: user types url-> domain.com  or www.domain.com  or https://www.domain.com

and he gets a 301 redirect to https://domain.com

as you probably know, google takes these URL's as different.

So far i've tried this combinations with no luck:



<rule name="Remove www" stopProcessing="true">
  <match url="(.*)" ignoreCase="true" />
  <conditions logicalGrouping="MatchAll">
    <add input="{HTTP_HOST}" pattern="^www\.(.+)$" />
    <add input="{HTTPS}" pattern="^www\.(.+)$" />
  </conditions>
  <action type="Redirect" url="https://{C:1}/{R:0}" appendQueryString="true" redirectType="Permanent" />
</rule>


    <rule name="Redirect everything to https:// on www domain" patternSyntax="Wildcard" stopProcessing="true">
      <match url="*" />
      <conditions logicalGrouping="MatchAny">
        <add input="{HTTP_HOST}" pattern="www.domain.com" negate="true" />
        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
      </conditions>
      <action type="Redirect" url="https://domain.com/{R:0}" redirectType="Permanent" />
    </rule>


anyone with the perfect rule?
9 years ago
See below the first 2 rules are required, I have added in the 3rd and 4th rule just because this is my policy on url rewriting to remove slashes and to lowercase the urls to prevent google indexing duplicate pages.

This is what you want:

<rule name="Redirect to WWW" stopProcessing="true">
          <match url=".*" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^domain.com.au$" />
          </conditions>
          <action type="Redirect" url="https://www.domain.com.au/{R:0}" redirectType="Permanent" />
        </rule>
        <rule name="Redirect to HTTPS" stopProcessing="true">
          <match url=".*" />
          <conditions>
            <add input="{HTTPS}" pattern="^OFF$" />
          </conditions>
          <action type="Redirect" url="https://{HTTP_HOST}/{R:0}" redirectType="Permanent" />
        </rule>
        <rule name="Lowercase URLs" stopProcessing="true">
          <match url="[A-Z]" ignoreCase="false" />
          <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
            <add input="{URL}" pattern="WebResource.axd" negate="true" />
            <add input="{REQUEST_METHOD}" matchType="Pattern" pattern="POST" negate="true" />
          </conditions>
          <action type="Redirect" url="{ToLower:{URL}}" />
        </rule>
        <rule name="Remove trailing slash" stopProcessing="true">
          <match url="(.*)/$" />
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          </conditions>
          <action type="Redirect" redirectType="Permanent" url="{R:1}" />
        </rule>
9 years ago
Actually I misread your URLs, I always redirect to https://www. so you will need to slightly modify my rules to remove the www. section of the redirects
9 years ago
Well thats kind of my problem,  I seem to get either https or non-www redirection but not BOTH... I will keep trying some diff combinations then.
6 years ago
Did you solve your problem?
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.