Get AI SEO for FREE.

Learn More!

How to Use Regex Redirects in Rank Math

As you’re aware, redirects enable you to forward one URL to another. It’s a smart way to send users and search engines to a different URL while preserving your search engine rankings for a particular page.

When visitors request previously available content on your site, but maybe since it has been moved, you want them to be redirected to your content’s new location and not get a 404 error.

Additionally, search engines must understand whether content has moved and whether that move is temporary or permanent.

Giving visitors and search engines the right signals for your website improves user experience and is essential to your SEO performance.

Regex—short for regular expression—is a valuable shorthand, extremely useful for setting up large numbers of redirects.

Imagine how massive it would be if you had to individually create separate redirects for hundreds of URLs. Like any language, you need to familiarize yourself with the basics. 

In this knowledgebase article, we’ll walk you through how to use regex redirects in Rank Math. Before using regex redirects in Rank Math, let’s first understand what a regex redirect is.

1 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 matches “abc” and “ab”
+One or more occurrences of the preceding element. ab+cd matches “abcd”, “abbcd”, “abbbcd”, and so on, but not “acd”.

2 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 WordPress Dashboard → Rank Math SEO.

2.1 Navigate to Redirections

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

Rank Math-Redirections

2.2 Add a New Redirection

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

Add New Redirection

2.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.

3 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.

Examples of regex redirects

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 to 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.

4. If you want to get rid of .html pages that have the /blog/ prefix and redirect all the posts in the directory, you’ll need to add the following in your source and destination URLs:

Regex Source URL:  /blog/(.*?)\.html
Destination URL:  /$1/

And the final result will be as

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.

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