Using Cloudflare to Redirect One Domain to Another
Redirecting a domain to another domain using Cloudflare can be accomplished by following these steps:
- Log in to Your Cloudflare Account: Access your Cloudflare account and go to the dashboard.
- Select the Domain: Choose the domain you want to redirect from the list of domains associated with your account.
- Access the DNS Settings: Navigate to the DNS settings page for your domain.
- Create a Dummy A Record:
- Add an A record for your domain.
- Set the name to
@
to represent the root domain or use a subdomain name. - Point it to
192.0.2.1
(this is a dummy IP address as the actual redirection will happen through page rules).
- Navigate to Page Rules: Go to the " Rules" section of your dashboard then to "Redirect Rules".
- Create a Redirect Rule for Redirection:
- Under Single Redirects, select Create Redirect Rule.
- Enter a descriptive name for the rule in Rule name.
- Enter your domain or subdomain in the format
*yourdomain.com/*
. This will ensure all paths are included in the redirect. - Choose the setting "Forwarding URL".
- Select the status code for redirection, typically
301
(Permanent Redirect) or302
(Temporary Redirect). - In the destination URL, enter the URL of the domain where you want to redirect. Make sure to include
http://
orhttps://
. - Under When incoming requests match, define the rule expression.
- Under Then, define the URL redirect settings for requests matching the rule expression.
- To save and deploy your rule, select Deploy. If you are not ready to deploy your rule, select Save as Draft.
- Save and Deploy: Save the rule and wait for a few minutes for the changes to propagate.
- Test the Redirect: Once the changes have propagated, test the redirect by visiting your original domain. It should automatically forward you to the new domain.
Remember that DNS changes might take some time to propagate globally, and the redirect should start working typically within a few minutes, but in some cases, it can take longer. Additionally, if you have any caching plugins or systems, clear them to ensure you're seeing the latest changes.