Sitecore Multi-site behind Azure FrontDoor

Azure FrontDoor can be instrumental in taking your Sitecore installation to the next level with added security, content delivery, and load balancing capabilities. However, the FrontDoor deployment can be tricky, especially if you’re dealing with a brand new Sitecore instance that doesn’t have any custom domains associated with the app services.

The application I was working with had a handful of sites hosted on one Sitecore installation. The problem we ran into was that although FrontDoor could route traffic from multiple domains to our app service, we only had a single domain on the app service to handle traffic through. Sitecore wasn’t able to differentiate which requests were for which website. All domains were displaying results for the same site.

To resolve this issue, we were able to make use of the X_Forwarded_For header that Azure FrontDoor includes with all requests. FrontDoor includes this header to indicate what domain the request was originally for. Utilizing a simple IIS UrlRewrite rule, we were able to overwrite the HTTP_HOST header. That allowed Sitecore to serve the right website content for each domain. You could also make use of the “x-original-host” header if you were running into this issue with an app gateway instead of Azure FrontDoor.

<rule name="Rewrite Domain {targetHost}">
	<match url="(.*)"/>
	<conditions>
		<add input="{HTTP_HOST}" pattern="{yourSite.azurewebsites.net}"/>
		<add input="{HTTP_X-Forwarded-Host}" pattern="{targetHost}"/>
	</conditions>
	<action type="None"/>
	<serverVariables>
		<set name="HTTP_HOST" value="{targetHost}"/>
	</serverVariables>
</rule>

By default, you can’t overwrite the HTTP_HOST header on an Azure app service. You will have to authorize the HTTP_HOST header to be overwritten by making an edit to the ApplicationHost.xdt file located in the “site” folder of your app service file directory.

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <system.webServer>
    <rewrite>
      <allowedServerVariables xdt:Transform="Replace">
        <add name="HTTP_HOST" xdt:Transform="InsertIfMissing" xdt:Locator="Match(name)" />
      </allowedServerVariables>
    </rewrite>
  </system.webServer>
</configuration>

After making this change, we were able to get Sitecore to properly serve content for all of our sites, with only a single domain in place on the app service. This saved us needing to make extra DNS CNAME records, and simplified our go-live strategy on our new website.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *