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 to 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:
2 Add a New Redirection
Add a new redirection from Redirections > Add New as shown below:
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.
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.
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/$1 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
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 need help?
Submit Your Question
Please give us the details, our support team will get back to you.