How to Set Up a Subdomain Redirect to Another Top-Level Domain in Cloudflare
You can use Cloudflare's Page Rules feature to redirect a subdomain to another top-level domain. Here are the detailed steps:
Method 1: Using Cloudflare Page Rules (Recommended)
Log in to your Cloudflare dashboard and select your domain
In the left navigation, click "Rules" > "Page Rules"
Click the "Create Page Rule" button
In the URL matching pattern, enter:
http://sub.yourdomain.com/*
or
https://sub.yourdomain.com/*
(choose HTTP or HTTPS based on your needs)
In the "Settings" section, select "Forwarding URL"
Choose the redirect type:
- 301 - Permanent redirect (SEO-friendly)
- 302 - Temporary redirect
Enter the destination URL (you can use the $1
wildcard to preserve paths):
https://newdomain.com/$1
Click "Save and Deploy"
Method 2: Using CNAME Record + Redirect Service
Add a CNAME record in Cloudflare DNS settings:
- Name: sub (your subdomain)
- Target: CNAME or A record of newdomain.com
Then set up redirect rules on the target domain's server
Important Notes
- SSL Certificate: If using HTTPS, ensure the target domain has a valid SSL certificate
- Caching: You may need to clear Cloudflare's cache after making changes
- Wildcards:
$1
preserves the path from the original URL
- Example:
http://sub.yourdomain.com/path
→ https://newdomain.com/path
- Multiple Rules: You can create multiple page rules for more complex redirects
Example Setup
If you want to permanently redirect shop.yourdomain.com
to example.com/store
:
- URL pattern:
https://shop.yourdomain.com/*
- Setting: Forwarding URL
- Status code: 301
- Destination URL:
https://example.com/store/$1
This way, visiting https://shop.yourdomain.com/products
will redirect to https://example.com/store/products