Skip to content

Page Rules for URL Forwarding & Redirects in Cloudflare

DodaTech Updated 2026-06-23 5 min read

In this tutorial, you'll learn about Page Rules for URL Forwarding & Redirects in Cloudflare. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.

Cloudflare Page Rules for URL forwarding let you create 301 and 302 redirects using wildcard patterns, preserving query strings or replacing URL segments without modifying your origin server configuration.

What You'll Learn

By the end of this tutorial, you will understand how to create forwarding Page Rules for domain migrations, protocol upgrades, path restructures, and SEO-friendly URL redirects using Cloudflare's pattern matching.

Why It Matters

URL redirects are essential for site migrations, fixing broken links, and enforcing HTTPS. Cloudflare Page Rules handle redirects at the edge before requests reach your origin, reducing server load and improving response times.

Real-World Use

Doda Browser's ad-blocker uses pattern matching to redirect tracking URLs to local blocks. The same wildcard logic applies to Page Rules: redirect entire directory structures with a single rule instead of configuring redirects on your origin server.

Your Learning Path

flowchart LR
  A[Page Rules Caching] --> B[Page Rules URL Forwarding]
  B --> C[More Cloudflare Features]
  B --> D{You Are Here}
  style D fill:#f90,color:#fff

Forwarding URL Action Types

Action HTTP Status Use Case
Forwarding URL 301 or 302 Permanent or temporary redirects with wildcard replacement
Always Use HTTPS 301 Redirect HTTP to HTTPS (automatic)
Automatic HTTPS Rewrites - Rewrite HTTP URLs in HTML to HTTPS

Wildcard Replacement Syntax

Pattern Forward URL Matches Redirects To
example.com/blog/* https://example.com/articles/$1 /blog/post-1 /articles/post-1
*example.com/* https://$1.example.com/$2 /page (from sub) sub.example.com/page
example.com/*/product https://example.com/$1/item /shop/product /shop/item
example.com/*.php https://example.com/$1 /about.php /about

Creating a Forwarding Rule

  1. Log in to the Cloudflare dashboard.
  2. Select your domain.
  3. Go to Rules > Page Rules.
  4. Click Create Page Rule.
  5. Enter the URL pattern with wildcards.
  6. Choose Forwarding URL as the action.
  7. Select 301 Permanent or 302 Temporary.
  8. Enter the destination URL using $1, $2 references.
  9. Save and deploy.

Common Redirect Scenarios

Scenario 1: Domain Migration

# Old domain to new domain with path preservation
# Pattern: *old-example.com/*
# Forward URL: https://new-example.com/$2
# Status: 301 Permanent Redirect

# Example: old-example.com/blog/post-1 -> new-example.com/blog/post-1
# The $2 captures everything after the domain.

Scenario 2: Directory Restructure

# Move all blog posts from /old-blog/ to /blog/
# Pattern: example.com/old-blog/*
# Forward URL: https://example.com/blog/$1
# Status: 301 Permanent Redirect

# Example: example.com/old-blog/hello-world -> example.com/blog/hello-world

Scenario 3: Remove File Extensions

# Convert .html URLs to clean URLs
# Pattern: *example.com/*.html
# Forward URL: https://$1.example.com/$2
# Status: 301 Permanent Redirect

# Example: example.com/about.html -> example.com/about
# Note: This requires a second rule to serve the actual .html file
# at the clean URL path.

Redirect with Query String Handling

// Cloudflare Worker for advanced query string redirects
export default {
  async fetch(request) {
    const url = new URL(request.url);
    const params = url.searchParams;

    // Redirect old campaign URLs to new structure
    if (url.pathname === '/landing' && params.has('campaign')) {
      const campaign = params.get('campaign');
      const newUrl = `https://example.com/campaigns/${campaign}`;

      return Response.redirect(newUrl, 301);
    }

    return fetch(request);
  }
};

// Expected behavior:
// GET /landing?campaign=summer2026 -> 301 to /campaigns/summer2026

Testing Redirects

# Test a 301 redirect from the command line
curl -I https://old-example.com/blog/test-post

# Expected output:
# HTTP/2 301 Moved Permanently
# location: https://new-example.com/blog/test-post
# cf-page-rule: Page-Rule-Matched

# Test with verbose output to see redirect chain
curl -L -o /dev/null -w "%{url_effective}" https://old-example.com/blog/test-post

# Expected output:
# https://new-example.com/blog/test-post

Common Errors

Redirect loop. If the destination URL also matches the same Page Rule, the request bounces between the two URLs. Always ensure the destination URL does not match the source pattern.

Both HTTP and HTTPS rules conflicting. If you have separate rules for http://example.com/* and https://example.com/*, they may conflict. Use *example.com/* for protocol-agnostic matching with an Always Use HTTPS rule.

Wildcard $1 references incorrect segment. Each * in the pattern corresponds to a numbered $ reference. Count from left to right: first * is $1, second is $2, and so on.

Case sensitivity. Cloudflare Page Rule patterns are case-insensitive. If you need case-sensitive matching, use a Cloudflare Worker.

Too many individual redirect rules. Each unique redirect path requires its own rule. For bulk redirects (100+), use a Cloudflare Worker with a redirect map instead of Page Rules.

Practice Questions

  1. How does the $1 wildcard reference work in a forwarding URL destination?
  2. What is the difference between a 301 and a 302 redirect in the context of SEO?
  3. How can you test a Cloudflare Page Rule redirect using curl?

Challenge

Plan a domain Migration from oldsite.com to newsite.com. The old site has the following paths: /blog/*, /products/*, /about.html, and a wildcard catch-all. Write the minimum Page Rules needed to preserve SEO equity during the Migration.

Real-World Task

Audit your production site for broken links using a crawler tool. For each broken URL category, determine whether a single Page Rule with a wildcard pattern can fix all matches. Implement the redirect.

FAQ

Can Page Rules forward to URLs with query strings?

Yes. The Forwarding URL destination can include static query strings. For dynamic query string forwarding, use the Preserve Query String option or a Cloudflare Worker that reconstructs the query from the original request.

Do Page Rule redirects affect SEO?

301 redirects pass most link equity to the new URL. Google treats 301 as permanent moves and transfers ranking signals. 302 redirects do not pass link equity. Use 301 for permanent changes and 302 for temporary ones.

Can I chain multiple redirect Page Rules?

Yes, but only the first matching Page Rule applies. If you need multi-step redirects (A -> B -> C), each intermediate URL must match its own Page Rule on the respective domain. Cloudflare Workers offer more flexibility for complex redirect chains.

  • Page Rules Intro — URL pattern matching fundamentals
  • Page Rules Caching — Combine redirects with cache control
  • Cloudflare — Complete platform guide

Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro — security-first tools for the modern web.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro