1. Home
  2. Knowledge Base
  3. SEO Suite
  4. How to Use Regex Redirects in Rank Math

How to Use Regex Redirects in Rank Math

In this knowledgebase article, we’re going to walk you through how to use regex redirects in Rank Math.

What is a Regex Redirect?

A Regex or a Regular Expression is nothing but a set of characters that helps find a pattern within a piece of text. It allows matching any number of URLs dynamically without even knowing what the URLs might be.

In the case of standard redirects, you can specify a source and a destination URL. A single source points to a single destination, but there may be situations where you’d want to redirect more than one source to a destination. This is when regex redirect comes into the picture and can match multiple source URLs and redirect them to the destination.

These are some of the common characters that are used in Regex Redirects:

*Zero or more occurrences of the preceding element. ab*cd matches “acd”, “abcd”, “abbcd”, “abbbcd”, and so on.
?Zero or one occurrence of the preceding element.abc? matches “abc” and “ab”
+One or more occurrences of the preceding element. ab+cd matches “abcd”, “abbcd”, “abbbcd”, and so on, but not “acd”.

How to Add Regex Redirects in Rank Math

Setting up a redirection has always been easy in Rank Math, thanks to its powerful Redirection Manager. With the help of Rank Math, you can manage your website’s redirections with the superhero-like powers bestowed in a complete Redirection Manager. Not only this, but it’s much easier to redirect large numbers of similar URLs with the help of its regex redirects option.

Note: Make sure you’ve installed Rank Math and activated the Redirection module from Rank Math > Modules section.

1 Navigate to Redirections

To add a regex redirect, navigate to Redirections from Rank Math’s dashboard as shown below:

Rank Math-Redirections

2 Add a New Redirection

Add a new redirection from Redirections > Add New as shown below:

Add New Redirection

3 Add Regex Redirect

Add your source URLs and select the matching option as Regex from the drop-down list. Add your destination URL, and make sure you activate the redirect. Click on Add Redirection to add the regex redirect.

Add Regex Redirect

And that’s it! Your regex redirect will then be added.

Examples of Regex Redirects

Let’s take a look at some of the examples that will help you to understand regex redirects in a better way.

Regex examples

1. If you want to get rid of the diacritic character and redirect all links with /ferñs/ to new /ferns/, you’ll have to add the following in your source and destination URLs:

Regex Source URL: /ferñs/(.*)
Destination URL: /ferns/$1

2. If you’ve used AMP on your website and later decided not to use it, you can redirect all AMP URLs back to the regular URLs. To achieve that, add the following in your source and destination URLs:

Regex Source URL: /(.*)/amp
Destination URL: /$1

3. A source URL /source/.* will match requests for:

  • /my-source/this
  • /my-source/that

And so on.

You can also check some of our other supported regexes and have a better understanding of regex redirects. Also, you can experiment with a pattern and tune it to match exactly what you want with the regular expression 101 tools.

Rank Math’s redirect manager fully supports Regex, using which you can create the most complex redirects with ease. However, if you still have any questions about using regex redirects in Rank Math, please feel free to contact our support team.

Was this article helpful?

Still not using Rank Math?

Setup takes less than 5 minutes including the import from your old SEO Plugin!

Learn more about the PRO Version

Still need help?


Submit Your Question

Please give us the details, our support team will get back to you.

Open Ticket

Related Articles