简体   繁体   中英

web.config force redirect of www to non-www with https

So currently my main domain works fine, if I go to www.domain.com it redirects to https://domain.com

my sub-domains are the issue. I have a wildcard SSL as well for *.domain.com

if I go to www.sub.domain.com, it redirects to https://www.sub.domain.com which has an invalid SSL cert and I am trying to get it to load FROM: www.sub.domain.com to https://sub.domain.com but am having some issues. Godaddy was no help as it seems most of them are "New". Hosting with Plesk unfortunately. Currently what I have for my web.config is:

<configuration>
<system.webServer>
<rewrite>
    <rules>
    <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>   
    </rules>
</rewrite>
</system.webServer>
</configuration>

Check for domains hosting settings like "preferred domain" and 301 redirect to HTTPS:

plesk https重定向

If you have no 301 redirect to HTTPS you can just delete this web.config.

Wildcard SSL Certificate cannot work on second level sub-domain when you have installed certificate for first level ( for example : level3.level2.level1.domain.com).

在此输入图像描述

You cannot use WWW before your sub-domain. I suggest you to refer my previous answer on the same issue.

https://stackoverflow.com/a/37959152/4649681

Hope this will help.

<rewrite>
   <rules>
       <clear />
       <rule name="Force WWW and SSL" enabled="true" stopProcessing="true">
         <match url="(.*)" />
         <conditions logicalGrouping="MatchAny">
           <add input="{HTTP_HOST}" pattern="^yourwebsite\.com$" negate="true"></add>
           <add input="{HTTPS}" pattern="off" />
         </conditions>
         <action type="Redirect" url="https://yourwebsite.com/{R:1}" appendQueryString="true" redirectType="Permanent" />
       </rule>
     </rules>
     <rewriteMaps>
       <rewriteMap name="MapProtocol">
         <add key="on" value="https" />
         <add key="off" value="http" />
       </rewriteMap>
     </rewriteMaps>
   </rewrite>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM