Skip to content

Rewrite Manager

Use the Rewrite Manager app in Enonic XP to create and maintain redirects for your site. It keeps the clutter outside of Content Studio and gives you more choices than regular shortcuts.

This app lets you maintain redirects in a much more powerful way than the limited offerings from Content Studio. It lets you administrate the redirects from a different tool, and nothing of it is visible from Content Studio. Often, shortcuts and redirects pollute the user experience in Content Studio, this app mitigates that.

How this app is used across Gjensidige's websites:

  • Stop users from meeting the 404-page for popular URLs/searches.
  • Create permanent redirects (status 301) when rebranding parts of the website.
  • Create redirects for commonly misspelled words.
  • Creating alias URLs (e.g. "car" and "cars" being sent to the same destination).
  • For short periods steer traffic to a temporary page (status 302) containing information.
  • Export/import redirects between servers
  • Test your redirects with the Request tester to see that they behave correctly
  • Configure redirects with files on the server

Not maintained by Gjensidige

This is one of many 3rd party applications running on Enonic XP used in our setups. It's part of Enonic's extended suite of applications. Documentation can be viewed on Enonic Market - it's a bit technical, detailing some cases not in use at Gjensidige.

Types of redirects

There are two types of redirects: permanent (301) and temporary (302).

The 301 redirect will be stored on servers as well as within each browser visiting it for about a year, sometimes longer. They are a bit difficult to delete/change, so they should only be used when certain.

The 302 redirect won't live forever, as browsers will try to visit again these URLs again at some point.

Which one to use is up to you, there's loads of material online to read if interested. An SEO specialist would argue to never use anything but 301 status, while a developer or DevOps engineer may argue that using only 301 quickly can lead you to errors in your redirects that will be very difficult to get rid of.

Keep track of your redirects

The Rewrite Manager is a very powerful tool in the right hands. With great power, comes great responsibility:

It's up to you to use other tools to monitor your redirects, clean them up when not needed anymore, and watch out for redirect loops.

Tools like httpstatus.io/ can be used for this, it can check bulks of URLs. We advise you to remove redirects after a few years, once they have depleted their usage.

Creating a redirect

1. Select the virtual host

  • Select your virtual host (vhost). It should be the only one in the table that contains rules (or the one with the most rules), and it is clickable.
  • If you are unsure or no vhost contains rules, consult a developer in MObile and web services, as it will not work if you select the wrong vhost.

2. Create a new rule

  1. Click the pen-icon inside the table to edit any redirect rule
  2. Click the "Create rule"-button in the top right corner to create a new redirect
  3. Always begin your rules with /, and never write the domain name
  4. Enter your new URL in "Pattern (source path)"
  5. Enter the page's current URL in "Substitution (target path)"
  6. Select a type of redirect.
  7. Leave the "Insert Strategy" as-is.
  8. Click Save to create it and it is instantly stored and available.
  9. Use the Request Tester tool in the menu to make sure everything went well.
1. Select the correct vhost
2. create the redirect rule

Using regex

The redirect rules support regular expressions (regex for short). These are powerful ways of writing logic into the redirect patterns. If you're not familiar with it, you should seek guidance from a developer.

The question mark

In its most basic form, you will see many question marks that just mean "the character to my left can be there, but it doesn't have to". So, /my-url/? would redirect both /my-url and /my-url/ to the new destination. It is very common to allow the trailing slash to be omitted.

Escaping

So, what happens if you must look for the character ? literally? Then you escape it using the \ character. Writing /my-url/\? would only match /my-url/? and no other URLs.

The dot

Not only ? character is a "functional" character in regex that might confuse you at first, also the . means "anything". So your redirect from /my.url/ would hit /my.url/ as expected, but also any other character, so also /my/url/ and /myxurl/ and /my_url/ and anything else would be redirected.

There's a lot more to do with regex, like using "capturing groups" to fetch multiple URLs with one rule. The path /my-url/(subfolder1|subfolder)/articles will match /my-url/subfolder1/articles and /my-url/subfolder/articles. Captured groups can also be stored and reused later in the actual redirect if you for instance want to construct a target like /my-new-url/articles?from=subfolder1 you could do that by using a capturing group and then typing a target like this /my-new-url/articles?from=$1.

Regular expressions are powerful and complicated, it's common even for developers to do mistakes. Consult Mobile and Web Services or your developers for assistance.