menu
Menu
Mobify DevCenter
search_icon_focus

Managing URL Redirects Using Mobify Cloud

Introduction

A URL redirect allows you to forward a request from a user or web crawler to a different URL. They’re a useful tool to ensure that users have the best experience when your application’s content changes. For example, you may have a seasonal campaign for spring at the path /spring. When you’re ready to retire the spring promotion and launch the summer campaign, you can use URL redirects to ensure that any visitors landing on /spring will automatically be redirected to the new campaign, at the path /summer. For more use cases, check out this blog article by Moz.com on Redirects.

In this article, we’ll walk you through the steps to create and manage URL redirects for your Mobify storefront from the Mobify Cloud user interface. This method provides a convenient way for ecommerce teams and other business users to manage redirects quickly and easily, without the need for code changes.

Note

You can also manage redirects by using the Mobify Cloud API or by extending your project’s App Server code.

Prerequisites

To manage redirects using Mobify Cloud, you’ll need:

  1. An account on Mobify Cloud with a role type of Redirector, Admin, Developer, or Deployer. If you don’t have an account, ask Mobify Support to create one for you.

  2. Some familiarity with targets. In Mobify Cloud, a target describes the environment that your app will run in. Most companies have a staging target to test changes and a production target where the live app runs. To learn more, read about Mobify’s Deployment Infrastructure.

  3. The names of your company’s staging and production targets

Assigning team roles

You may want to grant team members the ability to manage redirects while restricting their access to other functions in Mobify Cloud, such as deploying bundles. To achieve this, Admin users can assign a user to the Redirector role. This role has full access to the URL redirects functions of Mobify Cloud, but it’s restricted from managing bundles.

Note

The Admin, Developer, and Deployer role types can also manage redirects in Mobify Cloud. The Read Only and Designer role types can only view redirects.

For users with an Admin role type, follow these steps to create a new Redirector team member:

  1. Log in to Mobify Cloud
  2. Select your project
  3. Using the left side navigation, choose Settings
  4. In the Team Members section, select the Add Team Member button
  5. Specify the team member’s email, and choose the Redirector role

The workflow

To protect you from making errors, the URL Redirects UI feature supports this general workflow to manage redirects:

  1. Create your redirects (or make any changes) on your staging target
  2. Test your redirects on your staging target
  3. Clone your redirects from your staging to your production target

By using this suggested workflow, you can be confident that your changes to production will be an exact match of everything you set up and test on your staging target.

Creating a redirect

We recommend that you always create a redirect on your staging target, rather than in your production target. This allows you to test the redirect and verify that it works as expected.

Follow these steps to create a new redirect:

  1. Log in to Mobify Cloud
  2. Select your project
  3. Using the left side navigation, select URL Redirects
  4. Choose the Create Redirect button
  5. Select your staging target
  6. Enter a relative URL path in the Redirect From field. For example, to send visitors from the URL www.example.com/winter, enter /winter.
  7. Enter a relative URL path in the Redirect To field
  8. Specify Redirect Type
  9. Select the Create Redirect button

Redirect settings

The value that you enter in the From field must always be a relative path. The To field can be either a relative path or the full URL. For example, imagine we have a website called www.example.com, and we want to redirect visitors from www.example.com/spring to www.example.com/summer. The From field would require the format /spring. The To field would accept either /summer or www.example.com/summer.

Redirect types

Most redirects use the status code 301 (Moved Permanently). If you’re unsure which HTTP status code to use, consult this status code explainer from MOZ.com.

Forwarding query string parameters

Sometimes, your path may contain a query string parameter. For example, the relative path /spring-landing-page may have a query string appended to it for analytics tracking that’s unique for each user, becoming something like /spring-landing-page?gclid=123.

When creating redirects, you can select the option to Forward query string parameters. Selecting this option will append any existing query parameters to the To URL. If this option is not selected, query string parameters will be stripped from the path.

Note

What happens when your To path has a query string that you choose to forward, but the incoming request also has a query string? In this case, the resulting URL will be a combination of the two query strings. The query string from the To path is appended to the query string in the request. For example, if your application receives a request for the relative path /spring?year=2019 and you’ve chosen to redirect /spring to the path /summer?year=2020 with Forward query string parameters enabled, the resulting URL will be /summer?year=2019&year=2020.

Testing on staging

After the publishing process has completed (up to 20 minutes), test the redirect by selecting the hyperlink in the From field.

If your redirect isn’t working as expected, try these troubleshooting steps:

  • Clear your browser cache, because redirects are cached
  • Verify that you selected the correct target
  • Verify that you entered the From and To paths correctly

If needed, return to the URL Redirects screen in Mobify Cloud to edit the redirect and adjust its settings.

Repeat this process for all your redirects in the staging target so that you can clone your staging redirects into production with confidence.

Cloning to production

After you’ve completed testing on staging, you can clone all your redirects from staging into production. Here’s how:

  1. Log in to Mobify Cloud
  2. Select your project
  3. Using the left side navigation, choose URL Redirects
  4. Select the Clone Redirects button
  5. Specify your staging target in From Target
  6. Choose your production target in To Target
  7. Select the Clone Redirects button

Important

When you clone redirects, you’re replacing all the redirects in the production target with all the redirects in the staging target.

Best practices

  • Always test your changes by creating or editing redirects on a staging target and then cloning them to production

  • Always use the same staging target to manage redirects

  • For complicated redirects, such as wildcards or conditional redirects, manage them directly in your App Server code

Technical limitations

Redirects created in Mobify Cloud have the following limitations:

  • Each target can have a maximum of of 10,000 redirects

  • Each target has its own set of redirects, and it’s your responsibility to keep them in sync using cloning

  • Redirect URLs can contain wildcards only at the end of the URL.

  • Redirects URLs cannot contain conditionals.

  • Redirects created on Mobify Cloud do not run on a local development server. They only work on deployed targets.

  • Redirects don’t work for page transitions; they only work in response to an HTTP request.

Wildcard redirects

Redirect URLs can now be ended with the * character to indicate a wildcard. Wildcards will match any (0 or more) characters after the prefix. By example a redirect from /a/* would match /a/, /a/b and /a/b/c. Standard redirects will be processed first, followed by wildcards.

You can also now select to Forward Wildcard to append the wildcard path segment on to the To URL. By example /a/* matching /a/b/c to /z/ would end up at /z/b/c. You can find this checkbox on the Redirect create and edit form.

Request Processor considerations

If your path has been optimized for caching using Mobify’s Request Processor, the new optimized path will be used in the redirect operation.

A common example is when projects use the Request Processor to improve caching performance by filtering query strings. After filtering with the Request Processor, a relative path like /spring-landing-page?gclid=123 will become /spring-landing-page. In this case, /spring-landing-page would be used in the redirect operation.

Complex redirects

You can setup more complex redirects (like ones that use query string parameters) by extending the App Server code.