locked
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

    <rewrite>
      <rules>
    	<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\.)(.*)$" />
    	 </conditions>
    	 <action type="Redirect" url="https://{C:2}/{R:1}" appendQueryString="true" />
    	</rule>
    	<rule name="Force HTTPS" enabled="true" stopProcessing="true">
    	 <match url="(.*)" />
    	 <conditions logicalGrouping="MatchAny">
    	 <add input="{HTTPS}" pattern="off" />
    	 </conditions>
    	 <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" />
    	</rule>
      </rules>
    </rewrite>

    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.

      https://sg.godaddy.com/web-security/ssl-certificate


    Best Regards,

    WeiZhang

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

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

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

    Thursday, December 20, 2018 12:51 PM