MennaKearns
Crownpeak (Retired)

Implementing Rewrite rules

Web.config

For Windows/IIS we put redirects in the web.config. The most common approach is to use the developer template, which allows some code to be added and are still easily branchable. The web.config should be published to the site root. The rules are well documented by Microsoft and examples are available on support sites like Stack Overflow. It is important to note that incorrect values in the web.config will crash the site. Always test new rules in non-live states first prior to pushing live to ensure the change will not impact the live site.

Rewrite Map

When a large number of redirects are necessary, a rewrite map file can also be created. A rewrite map uses a simple name / value pair to process redirects, with the name or key the old url and the value the new url. The rewrite map is referenced within the web.config. It is important to note that rewrite map files being published alone will not enable the new redirect. It requires a restart of the site or an update to the web.config. For this reason with this approach usually accompanies a republish of the web.config with a change to ensure it publishes and does not skip. Rewrite maps must not repeat keys and much like web.config changes, invalid rules can impact the site so changes should be tested in non-live states first.

Much like the web.config, this file can be created with a developer template. However it is common to script out the output of the rewrite map file using template code. This allows either a collection of redirect assets or a field in templates to populate the rewrite list. A common approach is to add a old url field to a common input method. Then have the rewrite map asset render by pulling a filter list of assets with old urls referenced and build the redirect list from the old url field in multiple assets.

Labels (1)

Can't find what you are looking for?

Find Answers

Search our DXM Forum to find answers to questions asked by other DXM users.

Ask a Question

No luck? Ask a question. Our Product and Support teams are monitoring the Forum and typically respond within 48 hours.

Ask a Question