Redirection
Redirection policies enable automatic URL forwarding from one location to another with configurable HTTP status codes. The CDN system supports both permanent and temporary redirections using flexible pattern matching.
Redirection Configuration
HTTP Status Codes
Redirection policies support standard HTTP redirect codes:
- 301 Permanent Redirect: Indicates permanent URL change for SEO preservation
- 302 Temporary Redirect: Indicates temporary URL change without SEO impact
![Figure Needed] Screenshot showing redirection policy configuration with HTTP status code selection
URL Pattern Matching
Prefix Matching
Prefix matching applies redirection when the URL starts with a specified path:
- Directory Redirection:
/images
applies policy to all files within the/images
directory - Specific File Redirection:
/files/mydownload.zip
applies policy only tomydownload.zip
Regular Expression Matching
Regular expressions provide flexible pattern matching for complex redirection scenarios:
- File Extension Matching:
/video/.+\.mp4
matches all.mp4
files in the/video
directory - Pattern-Based Routing: Advanced URL transformation using regex patterns
Regular Expression Syntax
Perl-Style Syntax
The CDN policy system uses Perl-style regular expression syntax with specific rules and capabilities.
Reference Resource: Regular-Expressions.info provides comprehensive regex documentation.
Special Characters
Regular expressions use special characters that require escaping when used literally:
. [ { } ( ) \ * + ? | ^ $
Escaping Example:
- Pattern:
/animated$files
(incorrect - $ is special character) - Correct:
/animated\$files
(escaped with backslash)
Wildcard Patterns
Wildcard matching uses dots with repetition qualifiers:
.*
: Matches zero or more characters.+
: Matches one or more characters.?
: Matches zero or one character
Character Ranges
Square brackets define character ranges for pattern matching:
- Individual Characters:
[123456789]
matches any single digit 1-9 - Range Notation:
[1-9]
equivalent to above - Mixed Ranges:
[a-zA-Z0-9]
matches letters and digits - With Quantifiers:
[a-z]+
matches one or more lowercase letters
Alternation Patterns
Alternation allows matching multiple options using pipe notation:
Syntax: (pattern1|pattern2|pattern3)
Example: \.(mp4|ogg|swf)
matches files with .mp4
, .ogg
, or .swf
extensions
URL Anchoring Requirements
Path Matching Rules
Regular expressions must match complete URL paths:
- Leading Slash Required: Patterns must match the leading
/
in paths - Complete Path Matching: Pattern
filename.txt
will not match anything - Start-to-End Matching: Pattern
/file
matcheshttp://host/file
but nothttp://host/file.txt
Practical Examples
Exact Path Matching
- Pattern:
/files/august
- Matches: Only
/files/august
(not subdirectories) - Different from Prefix: Does not match
/files/august/document.pdf
Subdirectory Pattern Matching
- Pattern:
/files/.+/index.html
- Matches: All
index.html
files under/files/
directory regardless of subdirectory
File Extension Filtering
- Pattern:
/files/august/.+\.(mp4|ogg|swf)
- Matches: All
.mp4
,.ogg
, or.swf
files in/files/august/
- Note: Backslash escapes the dot to treat it as literal character
Policy Precedence
Multiple Match Resolution
When multiple redirection policies match a URL, the most specific policy is applied:
- Prefix vs Regex: Compare prefix length to regex leading text length
- Prefix Comparison: Longer prefix takes precedence
- Regex Comparison: Longest leading text before patterns takes precedence
- Subnet and Location: Additional criteria for equivalent matches
Specificity Examples
Prefix Precedence
/files/images/
(more specific) vs/files/
(less specific)- Longer prefix wins
Regular Expression Precedence
/files/images/.+\.jpg
vs/files/.+\.jpg
- First pattern has longer leading text (
/files/images/
)
Implementation Best Practices
Testing Procedures
- Test redirection policies with sample URLs before deployment
- Verify both matching and non-matching scenarios
- Check redirect status codes in browser developer tools
SEO Considerations
- Use 301 redirects for permanent URL changes to preserve search rankings
- Use 302 redirects for temporary changes or A/B testing
- Avoid redirect chains that impact performance
Performance Optimization
- Minimize complex regex patterns for better performance
- Use prefix matching when possible for simpler scenarios
- Monitor redirect usage through analytics to optimize patterns