How to Redirect a Subdomain to Another Using Cloudflare

If you need to redirect traffic from one subdomain to another, Cloudflare provides a simple and effective way to accomplish this using Page Rules or Redirect Rules. In this guide, we’ll walk you through setting up a redirect from https://old.example.com/* to https://new.example.com/*.

Why Use Cloudflare for Redirects?

  • Easy to manage – No need to modify your web server configuration.
  • Fast propagation – Cloudflare applies changes almost instantly.
  • Performance optimization – Redirects handled at the Cloudflare edge reduce load on your server.

Method 1: Using Cloudflare Page Rules

Page Rules allow you to define how Cloudflare handles traffic for specific URLs. Here’s how to set up a redirect:

Step 1: Access Cloudflare Dashboard

  1. Log in to your Cloudflare account.
  2. Select your domain (example.com).

Step 2: Create a Page Rule

  1. Navigate to Rules > Page Rules.
  2. Click Create Page Rule.
  3. In the If the URL matches field, enter: https://old.example.com/*
  4. Under Then the settings are, select Forwarding URL.
  5. Choose 301 (Permanent Redirect).
  6. In the Enter destination URL field, enter: https://new.example.com/$1 (The $1 ensures that all paths from old.example.com/* are preserved when redirected to new.example.com/*.)
  7. Click Save and Deploy.

Step 3: Test the Redirect

After saving the Page Rule, visit https://old.example.com/somepage in your browser and confirm that it redirects to https://new.example.com/somepage.


Method 2: Using Cloudflare Redirect Rules

Redirect Rules (under Transform Rules) provide more flexibility and scalability.

Step 1: Create a Redirect Rule

  1. In the Cloudflare dashboard, go to Rules > Redirect Rules.
  2. Click Create Rule.
  3. Under If the request matches, select:
    • HostnameEqualsold.example.com
  4. Under Then the settings are, choose Static Redirect.
  5. In the Redirect target, enter: https://new.example.com/$1
  6. Choose 301 Permanent Redirect.
  7. Save and Deploy.

Step 2: Verify the Redirect

Try visiting https://old.example.com/somepage to confirm it correctly redirects to https://new.example.com/somepage.

Conclusion

Using Cloudflare Page Rules or Redirect Rules, you can easily set up domain redirects without modifying your server settings. This ensures a smooth transition for users while maintaining SEO benefits. If you’re managing multiple subdomains, Cloudflare’s rules make it simple to handle complex redirects efficiently.

Leave a Comment