Redirect to your custom domain

This post assumes that you’ve already configured your custom domain, and here we are adding a step to ensure that the domain redirects there.

We achieve this by way of a URL rewrite, configured in the web.config:

            <rule name="Redirect to Custom Domain" stopProcessing="true">
                <match url=".*" />
                    <add input="{HTTP_HOST}" pattern="^(.*?)\.azurewebsites\.net$" />
                <action type="Redirect" url="{R:0}" appendQueryString="true" redirectType="Permanent" />

This will intercept any URL (^(.*?)$) and redirect it to your custom domain.

Adding Octopus Deploy to the mix

You most likely have multiple environments, and may need to redirect more than one to it’s own custom domain. Perhaps something like and etc.

This means that we’d want to specify a different target domain for the rewrite depending on the environment. We can achieve this my making use of the variable substitution feature in Octopus Deploy.

First, we define the variable in the config file:

<action type="Redirect" url="#{azureRedirectTarget}/{R:0}" appendQueryString="true" redirectType="Permanent" />

The #{azureRedirectTarget} variable now needs to be replaced by Octopus Deploy during deployment, based on the target environment.

First we turn the feature on:

Then we specify values for the new variable, like we normally would:

And now Octopus will replace the variable during deployment and our rewrite will be correct for each environment.