redirection.io rules cookbook

This documentation page lists several use cases and ways to achieve them by creating redirection.io rules.

Create a HTTP to HTTPs redirection

We fully support HTTP to HTTPs redirections, be it on the same domain or from one domain to another.

  • in the trigger "Source URL" field, type the absolute HTTP URL along with a marker of the anything type ;
  • in the action "Target URL" field, type the absolute HTTPS URL and use the previously created marker.

redirecting all the pages of a website from http to https

redirection.io supports many marker types, not only the anything type. In all the examples provided on this page, you can use the marker type that is best suited to your use case.

Redirect from a (sub-)domain to another

When deploying a website, it is a good practice to choose whether the raw domain should be used, or the www subdomain. Indeed, publishing your website on both example.com and www.example.com could create duplicate content, which is obviously something that you would not like.

Creating a (sub-domain) redirect can be achieved in a few steps:

  • in the trigger "Source URL" field, type the absolute URL without the scheme along with a marker of the anything type. Using a URL without scheme will apply the redirections to both the HTTP and HTTPs protocols ;
  • in the action "Target URL" field, type the absolute HTTPS destination URL and use the previously created marker. Of course, the destination domain can be the one of your choice, either the root domain, another sub-domain or a completely different one.

A redirection.io rule to redirect all the pages of a domain to a new one

Redirect several (sub-)domains to another one

In some cases, you will want to redirect several (sub-)domains to another one. Good news, in redirection.io, markers also work in the "domain" part of the URLs and can be combined!

Redirecting several domains

If you want to redirect several domains, type a URL of the form ://[DOMAINS]/[ANYTHING] in the trigger "Source URL" field, where:

  • [DOMAINS] is a marker that matches all the domains that you want to redirect. It can be a marker of the anything type, if you want to redirect all the domains associated proxyfied by this redirection.io project, or another type of marker (for example, a marker of the enum type if the domains to redirect is a finite list) ;
  • [ANYTHING] is a marker of the anything type

A redirection.io rule to redirect all the pages of several domains to a new domain

Redirecting several sub-domains of a given domain

If you want to redirect all the subdomains of a given domain, type a URL of the form ://[SUBDOMAINS].example.com/[ANYTHING] in the trigger "Source URL" field, where:

  • [SUBDOMAINS] is a marker that matches all the subdomains that you want to redirect. It can be a marker of the anything type, if you want to redirect all the subdomains, or another type of marker (for example, a marker of the enum type if the subdomains to redirect is a finite list) ;
  • [ANYTHING] is a marker of the anything type

Redirect URLs only when the backend generates a 404

Imagine that your website is displaying a list of ephemeral product pages under the /products path. These products come in limited quantity and, when they are out of stock, the page as it has been developed in the backend application disappears.

In this setup, which is rather frequent, product out of stock will generate a 404 error, which is a shame for several reasons:

  • the page must have been indexed by search engines, so users will stumble upon an error when visiting this page, which is not a positive thing for your brand image or your business ;
  • you loose the ability to have users discover your other products.

Automating redirections execution in this context can be achieved by adding the backend status response code trigger along to the Source URL trigger. In some steps:

  • in the trigger "Source URL" field, type the URL pattern for which redirects must be executed (so, use a marker of the anything type to match a group of pages).
  • add a BACKEND STATUS trigger requirement, and restrict this rule to be triggered only when a 404 error is about to happen

A redirection triggered for a set of URLs, only when the backend server would generate a 404 error

Rule triggers can be combined to restrict the conditions that will trigger the execution of a rule. If you have a specific use case that does not seem to be supported by our currently available triggers, please contact us to let us know your requirements!

Ignore the trailing-slash in URLs

There is a long-time debate about whether a URL ending with a slash should serve the same content as the URL without the trailing slash, and we often get questions from customers who would want their redirect to work both for a URL ending with a / and for the same URL without the final slash symbol.

The standards and RFC are clear: such URLs are not equivalent and represent different resources. This is why redirection.io treats such cases as different URLs. If you create a rule whole "Source URL" applies to /some-path/, it will not be triggered when a requests arrives on /some-path (and vice versa).

Real life, however, does not always perfectly fit the standards. For some of our customers, ignoring a trailing slash in the URLs matching process is a must-have, as their website comes with a long history of ignoring such trailing slashes. In some cases, the situation is even more cumbersome, as trailing slashes have to be ignored for some URLs of the website, but are important to be differentiated on other URLs.

Fortunately, redirection.io can help in such a case!

  1. Marker templates managementHead to the "settings" > "features" tab of your project, and scroll down to the "Marker templates" section
  2. Marker templates managementIn the "marker templates" section, create a new marker template. Call it "trailingslash", and use [TRAILING_SLASH] as the "CSV marker". If you import a CSV files containing exactly this string, it will be replaced with an instance of this marker template.
  3. Marker templates managementChoose the type “regex”, and use the following regex: /?
  4. Marker templates managementOnce the marker template has been defined, it can be used in the rule creation form

If you wish to ignore all the trailing slashes (not only one /, but also multiple trailing slashes like ///, for example, change the regular expression to use /*. When creating the rule, attach several examples to the rule, in order to check that it works as expected on the "impact" step:

Marker templates management

This page has been updated on November 25th, 2021.
Can't find your answer?