If you’ve ever needed to change a subdomain and ensure all traffic redirects seamlessly from the old subdomain to the new one, this guide is for you. In this tutorial, we’ll walk through the steps required to redirect one subdomain to another using Cloudflare, ensuring that every link, including subpages and query strings, redirects correctly.
Whether you’re consolidating domains, rebranding, or just organizing your web structure, this tutorial will show you exactly how to achieve a smooth transition with minimal downtime.
Why This Tutorial is Important
Redirecting a subdomain properly is crucial for maintaining SEO value, ensuring a good user experience, and avoiding broken links or lost traffic. The steps outlined here will help you set up a robust redirect that not only points the root of your old subdomain to the new one but also takes care of every link and path that was previously hosted on the old subdomain.
Step-by-Step Instructions
Step 1: Update DNS Settings
1. Log in to Your Cloudflare Account
- Navigate to the Cloudflare dashboard and select the domain associated with the subdomain you want to redirect.
2. Go to the DNS Section
- On the left-hand side menu, click on “DNS” to access the DNS settings for your domain.
3. Modify the Subdomain DNS Record
- Find the DNS Record: Locate the DNS record for your existing subdomain. This might be an A record or a CNAME record.
- Edit the DNS Record:
- Change the record to an A record if it’s not already one.
- Set the subdomain to point to Cloudflare’s proxied IP address:
192.0.2.1
. - Ensure the proxy status is set to “Proxied.”
- Save Your Changes:
- Click the “Save” button to apply the changes. This step ensures that Cloudflare manages the subdomain traffic, which is necessary for the redirection rule to work.
Step 2: Set Up the Redirect Rule
1. Navigate to the Rules Section
- In the left-hand menu of your Cloudflare dashboard, click on “Rules.”
2. Create a New Redirect Rule
- Select “Redirect Rules” from the options.
- Click on “Create a Rule” to start setting up your redirect.
3. Configure the Redirect Rule
- Name Your Rule: Give your rule a descriptive name, such as “Redirect members subdomain to my subdomain.”
- Set the Custom Filter Expression:
- Leave the filter set to “Custom Filter Expression.”
- Change the “Field” to “Host Name.”
- Set the “Operator” to “Equals.”
- Enter the old subdomain you wish to redirect (e.g.,
members.yourdomain.com
).
4. Define the Redirect Destination
- In the “Then” section, select “URL Redirect” as the action type.
- Choose Dynamic Redirect:
- Set the redirect type to “Dynamic.”
- Enter the Redirect Expression:
- Use the following expression to ensure all paths and query strings are preserved in the redirect:
concat("https://newsubdomain.yourdomain.com", http.request.uri.path)
- Replace
newsubdomain.yourdomain.com
with the subdomain you want to redirect to.
5. Set the Redirect Status Code
- Choose a 301 status code for the redirect. This tells search engines and browsers that the redirect is permanent, which is crucial for SEO.
6. Preserve Query Strings
- Make sure to check the option to “Preserve Query String.” This ensures that any parameters in the URL (like ?utm_source=google) are passed through to the new subdomain.
7. Deploy Your Rule
- Click “Deploy” to activate the rule.
Step 3: Minimize Downtime
To ensure minimal downtime, prepare both steps (DNS changes and redirect rules) in separate tabs. Execute them as quickly as possible. Due to Cloudflare’s rapid propagation, downtime should be no more than a few seconds, minimizing any disruption to your site traffic.
Conclusion
By following these steps, you can effectively redirect one subdomain to another using Cloudflare, maintaining all paths and query strings. This setup ensures a seamless transition for users and search engines, preserving both traffic and SEO value. If you want to see these steps in action, check out the video tutorial linked in this guide. However, following the written steps alone will enable you to complete this task without needing to watch the video.