5 Recepies for RegEx Redirects
Regular expressions are a set of characters used for defining a search pattern.
They can be used for creating unique redirects that will help you redirecting entire categories or links with similar parameters.
Redirect changing a URL query parameter to something else:
Redirect From: /\?referral_id=(?'rid'.*)
Redirect To: /?refid=[rid]
(note the backslash escaping the first ? question mark character)
Redirect changing part of the path in the URL
for example you changed the cateogry /oldcategory/ to /newcategory/ and you want URLs like /oldcategory/my-awesome-post/ to be redirected to /newcategory/my-awesome-post/
Redirect From: /oldcategory/(?'path'.*)
Redirect To: /newcategory/[path]
Redirect URL to remove date path from URL
for example redirect /2020/10/20/post-name/ to /post-name/
Redirect From: /\d{4}/\d{2}/\d{2}/(?'slug'.*)
Redirect To: /[slug]
Redirect all URLs to a new website.
Redirect From: /(?'path'.*)
Redirect To:
https://newwebsite.com/[path]
Redirect URLs using multiple named groups.
For example change date format from /2020/10/20/post-name/ to /20/10/2020/post-name/
Redirect From: /(?'y'\d{4})/(?'m'\d{2})/(?'d'\d{2})/(?'path'.*)
Redirect To: /[d]/[m]/[y]/[path]
Redirect URL if it contains certain keywords.
For example if it contains "apples", "oranges", "kiwi" anywhere in the URL redirect to /fruits/
/oldcategory/my-awesome-post/ to be redirected to /newcategory/my-awesome-post/
Redirect From: /.*(apple|orange|kiwi).*/
Redirect To: /fruit/