2

We have a Sitecore.NET 8.1 (rev. 160519) installation running IIS (version 8.5.9600.16384)

Our instance runs roughly 600 websites and we often have clients that switch their domain name after already being indexed (usually 1600+ pages) under the old one.

Our problem is that registrars such as GoDaddy do not offer HTTPS -> HTTPS redirects, only HTTP -> HTTPS. We are forcing https on all domains so they are all indexed under HTTPS.

We have a redirect module (https://github.com/thecadams/301RedirectModule/blob/master/documentation/301%20Redirect%20Module.pdf) in Sitecore, but it doesn't allow https://domainA.com -> https://domainB.com

Setting it up in IIS results in HTTP -> HTTPS working, but not HTTPS -> HTTPS.

Is there any easy way to implement this type of redirect either from Sitecore or IIS?

Thanks!

  • Have you considered using a service such as CloudFlare? You can setup redirects globally. – Michael West Sep 10 '19 at 15:00
  • @MichaelWest I do not believe a CloudFlare subscription would be in our scope. If it affected all 600+ websites then it would be a different story. – NoMonitor Sep 10 '19 at 15:10
2
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="newmexicomastersswimming">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTP_HOST}" pattern="^www\.domain1\.org$" />
                    </conditions>
                    <action type="Redirect" url="https://domain1.org/{R:1}" />
                </rule>
                <rule name="HTTP to HTTPS redirect" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTPS}" pattern="^OFF$" />
                        <add input="{REQUEST_URI}" pattern="/sitecore/api/.*" negate="true" />
                        <add input="{REQUEST_URI}" pattern="/ahp.aspx" negate="true" />
                    </conditions>
                    <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

Lets break it down

Single URL

This rule will redirect a single domain from anything www.domain1.org to https://domain1.org. And the nice part of this is that it does not require a www.domain.org SSL cert. Just domain.org SSL cert is needed. You can add as many of these rules as you want.

<rule name="domain1">
    <match url="(.*)" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="^www\.domain1\.org$" />
    </conditions>
    <action type="Redirect" url="https://domain1.org/{R:1}" />
</rule>

Catch all

This rile is the catch all rule that will take ANY HTTP request and flip it to HTTPS. I have also included some exclusions /sitecore/api/.* and /ahp.aspx in case you have a requirement to not force a URL to redirect. An issue I had with FXM and CORS.

<rule name="HTTP to HTTPS redirect" stopProcessing="true">
    <match url="(.*)" />
    <conditions>
        <add input="{HTTPS}" pattern="^OFF$" />
        <add input="{REQUEST_URI}" pattern="/sitecore/api/.*" negate="true" />
        <add input="{REQUEST_URI}" pattern="/ahp.aspx" negate="true" />
    </conditions>
    <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
</rule>
  • Thank you for the reply Chris, We are going to work on implementing a mix of your code and Surya's tomorrow morning. Do you by chance know what database is written to once the web.config file is saved? We ran into a corruption issue a few years ago that wasn't resolved even after restoring the file and had to restore the whole server from a backup to resolve the issue. Thanks! – NoMonitor Sep 12 '19 at 18:19
  • 1
    Database? A web.config change writes no changes to a database. This is actually completely IIS level stuff. Doesn't even involve Sitecore. It is so low in the web request stack. – Chris Auer Sep 12 '19 at 19:00
  • Thanks Chris! We will back up all IIS related files. – NoMonitor Sep 12 '19 at 19:11
  • Just to verify, we are talking about the web.config in the Sitecore root folder, correct? – NoMonitor Sep 12 '19 at 20:06
  • 1
    Yes. And FYI you should be transforming the web.config in visual studio and deploying the output. Not just editing the one on the website. – Chris Auer Sep 12 '19 at 21:17
3

This IIS Rule should work for both HTTP and HTTPS

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="SiteA to SiteB" stopProcessing="true">
                     <match url="(.*)" />
                     <conditions>
                            <add input="{HTTP_HOST}" pattern="^(www.)?sitea\.com$" />
                     </conditions>
                     <action type="Redirect" url="https://www.siteb.com/{R:1}" redirectType="Permanent" />
                </rule>                
            </rules>
      </rewrite>
    </system.webServer>
</configuration>
  • Thank you for the reply Surya, We are going to work on implementing a mix of your code and Chris' tomorrow morning. Do you by chance know what database is written to once the web.config file is saved? We ran into a corruption issue a few years ago that wasn't resolved even after restoring the file and had to restore the whole server from a backup to resolve the issue. Thanks! – NoMonitor Sep 12 '19 at 18:16
  • 1
    @NoMonitor web.config is just a file having various settings to function an asp.net applications. Sitecore application is also just an asp net application and It has nothing to do with any database. Since this config file may have settings related to database, it doesn't mean when you update web.config it updates any database. – Surya Sep 12 '19 at 20:34
  • Thanks again Surya! Used a bit of your code and most of Chris' code to implement our redirect without issue! – NoMonitor Sep 13 '19 at 14:38
  • @NoMonitor Glad that this answer was helpful but can you explain what part you copied from Chris's answer? Because your question was specifically for redirecting requests from https to https for the whole site and this rule should be enough to address that. – Surya Sep 13 '19 at 20:00
  • I added (www.)? to the input URL line and added redirectTyle="Permanent" since we want to delist from Google SERP the old domain. I realize we could request the de-index directly from Google but we would rather preserve legacy link's functionality so this is our best option. I only selected Chris' answer because it's the one we tried and it worked. Thanks again! :) – NoMonitor Sep 16 '19 at 20:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.