WEBtechSupport Website Technology Blog

How to Redirect Traffic Using Cloudflare: A Step-by-Step Guide

Written by Andras V. | 11/22/24 3:16 PM

Managing web traffic redirection can be tricky, especially when dealing with exceptions. Recently, I needed to redirect all traffic from my old domain, floatingpint.com, to my new site, webtechsupport.co.uk, while keeping a specific path (/seo-tool) pointing to another subdomain. Here’s how I achieved it using Cloudflare.

Why Use Cloudflare for Redirection?

Cloudflare is a powerful tool for DNS and traffic management. Its Page Rules feature makes it easy to set up conditional redirects without requiring server-level configuration. This guide will show how you can:

  • Redirect a specific path (e.g., /seo-tool) to a different domain or subdomain.
  • Redirect all other traffic from a domain to another site.

Step 1: Set Up DNS Records in Cloudflare

  1. Log into Cloudflare and add your domain (floatingpint.com) if it’s not already there.
  2. Confirm your existing DNS records:

    • Add an A record for the root domain (@) pointing to a placeholder IP, such as 192.0.2.1.
    • Add a CNAME record for www.floatingpint.com pointing to floatingpint.com

Step 2: Configure Page Rules for Redirects

Page Rules in Cloudflare allow you to manage conditional traffic redirection.

Rule 1: Redirect /seo-tool to a Specific URL

  1. Navigate to Rules > Page Rules in the Cloudflare dashboard.
  2. Click Create Page Rule and set:

  3. Save the rule.

Rule 2: Redirect All Other Traffic to Another Domain

  1. Create another Page Rule with:
    • URL Pattern: floatingpint.com/*
    • Setting: Forwarding URL (301 Permanent Redirect)
    • Destination URL: https://webtechsupport.co.uk/$1

      The $1 ensures that any path after the domain is appended to the new site.

  2. Drag this rule below the /seo-tool rule so it’s applied only after the specific match.

Step 3: Verify and Test Your Setup

  1. Test the redirection rules:
    • Visit floatingpint.com/seo-tool → Redirects to https://seo.webtechsupport.co.uk.
    • Visit any other path (e.g., floatingpint.com/about) → Redirects to https://webtechsupport.co.uk/about.

  2. Use tools like Redirect Checker to confirm the rules are working correctly.

Why This Method Works

Cloudflare’s Page Rules prioritize specific rules over catch-all ones. By ordering the /seo-tool rule before the global redirect, you ensure exceptions are handled correctly. The flexibility of DNS and redirection settings in Cloudflare makes it an ideal solution for similar use cases.

Conclusion

Redirecting traffic might seem daunting at first, but with tools like Cloudflare, it becomes manageable. This method allows you to retain control over specific paths while efficiently forwarding users to your new site.

If you’re facing similar challenges or have questions, feel free to reach out or leave a comment below!