Regex Redirects (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
| Pattern | Meaning | Example |
|---|---|---|
| . | Any single character | a.c matches abc, a1c, a@c |
| * | Zero or more of previous | ab* matches a, ab, abbb |
| + | One or more of previous | ab+ matches ab, abbb |
| ? | Zero or one of previous | colou?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 operator | cat|dog matches cat or dog |
| \d | Any digit | \d4 matches 2024 |
| \w | Word character | \w+ matches hello_world |
Creating Regex Redirects
Step-by-Step Guide
- Enable Regex ModeCheck "Use Regular Expression" when creating a redirect
- Write Pattern for Source URL
^/old-category/(.*)$ # Matches: /old-category/anything # Captures: "anything" as $1 - Use Captured Groups in Target
/new-category/$1 # If source matched /old-category/post-title # Target becomes /new-category/post-title - Test Your PatternUse the built-in regex tester to verify matches
- Set PriorityHigher priority for more specific patterns
Common Regex Redirect Patterns
Remove File Extensions
Source: ^(.*).html$
Target: $1
Example: /page.html → /pageDate-Based URLs to Flat Structure
Source: ^/d{4}/d{2}/d{2}/(.*)$
Target: /blog/$1
Example: /2024/03/15/my-post → /blog/my-postCategory Migration
Source: ^/blog/category/([^/]+)/(.*)$
Target: /topics/$1/$2
Example: /blog/category/seo/guide → /topics/seo/guideLowercase URLs
Source: ^/Products/(.*)$
Target: /products/$1
Example: /Products/Widget → /products/WidgetRemove Query Parameters
Source: ^([^?]+)?.*$
Target: $1
Example: /page?utm_source=email → /pageWWW to Non-WWW
Source: ^https://www.(.*)$
Target: https://$1
Example: https://www.site.com/page → https://site.com/pageAdvanced 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 groupsOptional 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 optionalConditional 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 optionsTesting Regex Patterns
Built-in Testing Tool
ProRank SEO includes a regex testing tool to verify your patterns before saving:
- Enter Pattern:Type your regex pattern in the Source URL field
- 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 - Preview Results:See what the target URL will be for each match
- 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 onlyGreedy 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 periodRegex 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.