ProRank SEO

Regex Redirects (Pro+)

Pro+

Advanced pattern matching for powerful redirect rules

Pro+ Feature: Regex redirects require a Pro+ license. They allow you to create powerful pattern-based redirects that can handle thousands of URLs with a single rule.

What are Regex Redirects?

Regular Expression (Regex) redirects use pattern matching to redirect multiple URLs that follow a similar structure. Instead of creating individual redirects for each URL, you can create one regex rule that handles all matching patterns.

Benefits of Regex Redirects

  • Handle thousands of URLs with one rule
  • Dynamic URL parameter handling
  • Complex pattern matching
  • Reduce database size
  • Easier maintenance
  • Better performance at scale

Regex Syntax Basics

Common Pattern Elements

PatternMeaningExample
.Any single charactera.c matches abc, a1c, a@c
*Zero or more of previousab* matches a, ab, abbb
+One or more of previousab+ matches ab, abbb
?Zero or one of previouscolou?r matches color, colour
^Start of string^/blog matches /blog/post
$End of string.html$ matches page.html
()Capture group/(.*) captures everything
[]Character class[0-9] matches any digit
|OR operatorcat|dog matches cat or dog
\dAny digit\d4 matches 2024
\wWord character\w+ matches hello_world

Creating Regex Redirects

Step-by-Step Guide

  1. Enable Regex ModeCheck "Use Regular Expression" when creating a redirect
  2. Write Pattern for Source URL
    ^/old-category/(.*)$
    # Matches: /old-category/anything
    # Captures: "anything" as $1
  3. Use Captured Groups in Target
    /new-category/$1
    # If source matched /old-category/post-title
    # Target becomes /new-category/post-title
  4. Test Your PatternUse the built-in regex tester to verify matches
  5. Set PriorityHigher priority for more specific patterns

Common Regex Redirect Patterns

Remove File Extensions

Source: ^(.*).html$
Target: $1
Example: /page.html → /page

Date-Based URLs to Flat Structure

Source: ^/d{4}/d{2}/d{2}/(.*)$
Target: /blog/$1
Example: /2024/03/15/my-post → /blog/my-post

Category Migration

Source: ^/blog/category/([^/]+)/(.*)$
Target: /topics/$1/$2
Example: /blog/category/seo/guide → /topics/seo/guide

Lowercase URLs

Source: ^/Products/(.*)$
Target: /products/$1
Example: /Products/Widget → /products/Widget

Remove Query Parameters

Source: ^([^?]+)?.*$
Target: $1
Example: /page?utm_source=email → /page

WWW to Non-WWW

Source: ^https://www.(.*)$
Target: https://$1
Example: https://www.site.com/page → https://site.com/page

Advanced Patterns

Complex Examples

Multiple Capture Groups

Source: ^/shop/([^/]+)/([^/]+)/item-(d+)$
Target: /products/$1-$2/id/$3
Example: /shop/electronics/phones/item-123 → /products/electronics-phones/id/123

Explanation:
([^/]+) = Captures any characters except /
(d+) = Captures one or more digits
$1, $2, $3 = References to captured groups

Optional Parameters

Source: ^/article/([^/]+)(?:/page/(d+))?/?$
Target: /blog/$1?page=$2
Examples:
/article/seo-guide → /blog/seo-guide?page=
/article/seo-guide/page/2 → /blog/seo-guide?page=2

(?: ) = Non-capturing group
? after group = Makes it optional

Conditional Redirects

Source: ^/(en|es|fr)/(.*)$
Target: /$2?lang=$1
Examples:
/en/about → /about?lang=en
/es/about → /about?lang=es
/fr/about → /about?lang=fr

(en|es|fr) = Matches any of these options

Testing Regex Patterns

Built-in Testing Tool

ProRank SEO includes a regex testing tool to verify your patterns before saving:

  1. Enter Pattern:Type your regex pattern in the Source URL field
  2. Test URLs:

    Enter test URLs to verify matches:

    /old-category/post-1 ✓ Matches
    /old-category/sub/post-2 ✓ Matches
    /new-category/post-3 ✗ No match
  3. Preview Results:See what the target URL will be for each match
  4. Check Capture Groups:Verify that groups capture the expected values

Performance Considerations

Optimization Tips

Pattern Efficiency

  • • Use anchors (^ and $) to avoid unnecessary matching
  • • Be specific rather than using .* everywhere
  • • Use character classes [a-z] instead of wildcards when possible
  • • Avoid excessive backtracking with nested quantifiers

Priority Management

  • • More specific patterns should have higher priority
  • • General catch-all patterns should have lowest priority
  • • Test order of execution with overlapping patterns

Regex redirects are processed after exact match redirects. Keep the number of active regex patterns reasonable (< 100) for optimal performance.

Common Mistakes

Forgetting Anchors

Wrong: /old/(.*)
This matches: /old/page, /folder/old/page

Correct: ^/old/(.*)$
This matches: /old/page only

Greedy Matching

Wrong: ^/blog/(.*)/(.*)$
For /blog/2024/03/post, captures: $1="2024/03" $2="post"

Better: ^/blog/([^/]+)/(.*)$
Captures: $1="2024" $2="03/post"

Escaping Special Characters

Wrong: ^/page.html$
The . matches any character!

Correct: ^/page.html$
The . matches literal period

Regex Redirect Limits

Pro+ License Features

  • Unlimited regex patterns
  • Complex pattern support
  • Multiple capture groups
  • Backreference support ($1, $2, etc.)
  • Pattern testing tool
  • Import/export regex rules

Without Pro+ license, regex redirect options will be disabled in the interface. Upgrade to Pro+ to unlock this powerful feature.