What are the different types rules in Cloudflare?
1. Transform Rules
- Most powerful and flexible
- Processes requests at the edge (before reaching origin)
- Can modify request/response headers, URL components, and HTTP headers
- Lowest latency since changes happen at edge
- Limited to Enterprise plans
- Best for: Complex transformations and request modifications
2. URL Rewrite Rules (Configuration Rules)
- Changes the URL before the request reaches your origin server
- No HTTP redirect (client sees original URL)
- Available on all plans
- Works at edge level
- Best for: Internal URL restructuring without user-visible changes
3. Page Rules
- Simplest to set up
- Can handle redirects, caching, security settings
- Limited number based on plan
- Processes sequentially (order matters)
- Higher priority than other rules
- Best for: Simple redirects and page-specific settings
Key Differences Table:
Feature | Transform Rules | URL Rewrite Rules | Page Rules |
---|---|---|---|
Plan Availability | Enterprise only | All plans | All plans |
Number of Rules | Unlimited | Unlimited | 3-125 (plan dependent) |
Client-visible URL change | No | No | Yes (for redirects) |
Processing Location | Edge | Edge | Edge |
Complexity | High | Medium | Low |
Use Case | Complex transformations | Internal rewrites | Simple redirects |
Performance Impact | Lowest | Low | Low |
Header Modification | Yes | No | Limited |
Priority Order | After Page Rules | After Page Rules | Highest |
For your specific case of redirecting /media to a CDN:
- If you want users to see the CDN URL: Use Page Rules with a redirect
- If you want to keep the original URL but serve from CDN: Use URL Rewrite Rules
- If you need complex logic or header modifications: Use Transform Rules (if available)