Massive Redirect for Domain Migration

Edit on GitHub

Edge Function Massive Redirect is a serverless solution from Azion’s Edge Computing platform for processing large numbers of redirects, which can be employed where there is a need to alter a significant number of addresses, as domain migrations for example.

This application allows you to control redirects directly at the edge of the network, centralizing the management of several settings in one place. This allows you to handle different situations, such as migrating a CMS or e-commerce platform, website updates, etc.

Some of the other advantages of using Edge Function Massive Redirect to deal with a domain migration:

  • Manage multiple redirects centrally, without needing to create a Request Phase Rule for each redirect;
  • Reduce the negative impact on your SEO;
  • Reduce the risk to your search engine ranking for the affected pages; and
  • Allows processing to be executed on the Edge, freeing up resources from the origin infrastructure.

Next, let’s see how Edge Function Massive Redirect works and how to use it.

How it works

The function deals with the redirection of traffic according to settings established using Args parameters and validation criteria defined in the Rules Engine of Edge Application.

When a request to an address, for which settings have been configured in the parameters, reaches any of the Azion Edge Nodes, the function identifies that it must be redirected and forwards it to the new address. The originating application, in turn, receives the request and returns the content so that the Edge node can send it to the user with the corresponding HTTP status (301 or 302, depending on the setting).

Redirects that need to be executed by the function, are defined using a list of parameters in JSON format, formed of pairs containing the old address and the destination address (the Args), as shown here:

  • old address: this can be listed exactly or by using a regular expression from the options below:
    • From: full address;
    • from_regex: regular expression to represent a standard URL format, allowing you to configure more than one address using a single rule. These expressions must be in the form of Perl Compatible Regular Expressions (PCRE) patterns
  • destination address: can be written in two ways:
    • moved: destination location (Url) to which it is going to be permanently redirected (HTTP status 301);
    • found: destination location (Url) to which it is going to be temporarily redirected (HTTP status 302);

Therefore, the configuration of a list of redirects would have the following format:

[{
   "from": "https://www.old-site.com",
   "moved": "https://www.new-site.com"
},
{
    "from": "https://www.old-site.com/shoes-snekears.html",
    "moved": "https://www.new-site.com/category/shoes/sneakers"
},
{
    "from": "https://www.old-site.com/users-login.html",
    "found": "https://www.new-site.com/login.html"
},
{
    "from_regex": "https://(api|store|checkout)\\.old-site\\.com$",
    "moved": "https://www.new-site.com/%1$"
}]

List with multiple redirects in a single Args configuration.

Based on the information contained in the Args, the function will carry out an interpretation of addresses and redirects, as we will see in detail next.

Configuring the Massive Redirect function

The Edge Function Massive Redirect is available from the functions library of Azion’s Edge Computing platform and can be accessed through Real-Time Manager (RTM), from the Libraries menu.

The function can only be executed when it has been instanced in the Edge Application that you intend to work in and when the activation criteria and behaviors have been defined in the Rules Engine..

Creating an Instance

Path: Real-Time Manager > Edge Computing > Edge Application > Functions.

Enter RTM and select the Edge Application that is going to run the function and activate the Edge Functions module, on the Main Settings. Then, on the Functions tab, add a new function, ensuring that you give it a memorable name.

Parameters: You need to include the type of function for your instance, in this case choose Massive Redirect. Note that the function code that appears in the Code field, is just for information. On the Args tab enter a list of the addresses to be redirected and their respective destinations, as in the example below, and save this function.

[{
    "from": "https://www.old-site.com",
    "moved": "https://www.new-site.com"
},
{
    "from_regex": "https://(api|store|checkout)\\.old-site\\.com$",
    "moved": "https://www.new-site.com/%1$"

}]

Example of the configuration of Args parameters

Defining the Execution criteria (Rules Engine)

Path: Real-Time Manager > Edge Computing > Edge Application > Rules Engine.

The rules (Rules Engine) determine the set of conditions that need to be met for Behaviors to be executed. You can either use the Default Rule or create a new one to set the parameters for validating and the behaviors that the Edge Application will execute.

Defining validation criteria (criteria): choose the variables, comparison operators and strings to create your business rule, as in the example below:

If: ${domain} is equal old-site.com (next: logical operator, variable, comparison operator, string)

In this example, if the domain accessed is the same as the string “old-site.com”, the rule will be executed.

Defining Behaviors (behaviors): add the behaviors you want to be carried out when the rule’s conditions are met, as in the example below:

  • Then: Run Function MyMassiveRedirect (next: logical operator, action, function)

In this example, if the conditions defined in the rules are satisfied, then the function MyMassiveRedirect will be executed.

Just save and your Edge Application will be ready to run this new function.


Didn’t find what you were looking for? Open a support ticket.