Redirect https://www to none www not working in asp.net RRS feed

  • Question

  • User-1646292712 posted

    My web using code asp.net (C#) in visual studio 2015. My web using ssl not redirect https://www to none www hicc.

    ex: https://www.trungtamthuoc.com error to https://trungtamthuoc.com

    while www.trungtamthuoc.com redirect good to https://trungtamthuoc.com

    Code redirect in web.config : hellp me huhuhu

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

    Wednesday, December 12, 2018 3:08 AM

All replies

  • User-1174608757 posted

    Hi trungtamthuoc.com

       https://www.trungtamthuoc.com and https://trungtamthuoc.com are two different domains.If public key certificates you buy can only protect only one website,you couldn't use https  to visit its sub-domains.To accomplish your requirement,you could  use the Wildcard SSL. 

    A Wildcard SSL protects your primary domain and an unlimited number of its subdomains. For example, a single Wildcard Certificate can secure both www.coolexample.com and blog.coolexample.com.  Here is the link ,I hope it will hep you.


    Best Regards,


    Thursday, December 13, 2018 7:17 AM
  • User-2054057000 posted

    Kindly use the below rule for your web.config file.

      <rule name="CanonicalHostNameRule1">
        <match url="(.*)" />
    	<add input="{HTTP_HOST}" pattern="^www\.trungtamthuoc\.com$" negate="true" />
          <action type="Redirect" url="https://www.trungtamthuoc.com/{R:1}" />
      <rule name="Canonical Redirect" enabled="true" stopProcessing="true">
        <match url="^index.html$|^index.htm$|^default.asp$|^default.aspx$|^index.aspx$" /> 
      <action type="Redirect" url="/" />

    Thursday, December 20, 2018 12:51 PM