Go to main content Go to main menu

Making Redirects Environment-Aware in Optimizely CMS with Geta NotFound Handler

By Wezz Balk Reading time: 1 minute

Managing redirects across multiple environments in Optimizely CMS can be a challenge, especially in a multi site solution. Redirects can often contain domain-specific paths, and harmonizing content between environments, domain-specific redirects can easily break. We've got a solution for that.

The Problem

The problem is not exclusive to multi-sites solutions and is commonly seen when hosted in a multi-environment (ex. integration, preproduction and production environment) such as Optimizely DXP.

When harmonizing content from production back to the other environments (which is best practice to do regularly), some content can unfortunately break unless it's handled correctly. 

If you've done nothing, then the content will not be truly harmonized since domain-specific redirects will stop to work. Doing a crawl of both the production and preproduction environments will render two completely different results when it comes to the redirects, and we don't want that.  

The Solution

By leveraging the environment sync capabilities of Addon.Episerver.EnvironmentSynchronizer and Geta NotFound Handler, we can automatically fix redirects during startup or after an environment sync. The class I’ve written, GetaRedirectDomainEnvironmentSynchronizer, does exactly that.
It runs as part of the environment sync process and modifies existing redirects so they align with the current environment’s domain setup.

 

How to Use It

Installation is simple:

  1. Add the class GetaRedirectDomainEnvironmentSynchronizer to your Optimizely CMS project.
  2. Make sure both Geta NotFoundHandler and Addon.Episerver.EnvironmentSynchronizer are installed and configured.
  3. Harmonize your environments (the sync only works if the site GUIDs match) and the environment configuration in appsettings is up to date.

They are both available in the Optimizely NuGet feed.

 

What It Does

  • Looks through the environment synchronizer settings to figure out what domains are used per site
  • Replaces irrelevant domains in redirects with the domains relevant for the current environment (this is done on a per-site basis)

Why It Matters

This small addition can save hours of debugging and manual redirect fixing. It’s especially useful for teams deploying frequently across multiple environments, or for site owners who want to ensure a smooth experience regardless of where the site is running.

Having your test-environment continuously harmonized will ensure you don't spend time reproducing content to test with, and your test environments do what they're supposed to do, help you test.

Source Code

You can find the full class here:
👉 GetaRedirectDomainEnvironmentSynchronizer on GitHub Gist

Need more help?

Just reach out! We offer expert services and more.

 

We would like to hear what you think about the blog post

Wezz Balk

Wezz Balk

Developer | Tech Lead

Read all blog posts by Wezz Balk