Redirect website from 1 domain to another
Say I have 2 domains, domain1.com and domain2.com. Both are on cloudflare. domain1.com is an old website with multiple URLs like domain1.com/blog or domain1.com/categories. Now I want all old domain and it sub URLs to open on the new domain, which means
1. domain1.com should open domain2.com
2. domain1.com/blog should open domain2.com/blog etc
I have tried the page rule for URL forwarding https://developers.cloudflare.com/rules/page-rules/how-to/url-forwarding/, but that doesn't work. What should I do to make this work?
18 Replies
Can you clarify "doesn't work"? What was the rule you set and what part doesn't work
Have you tried: https://developers.cloudflare.com/rules/url-forwarding/single-redirects/examples/#redirect-all-requests-to-a-different-hostname
Cloudflare Docs
Single Redirects — Example rules · Cloudflare Rules docs
The following sections contain example single redirect rule configurations.
Page Rule - forwarding URL
https://www.domain1.com/* to https://www.domain2.com/$1 with 302 temp redirect
no, i checked page rules first as this was what other support forwarded to me and I want to confirm before doing anything else
This is what I use and I can confirm it works
maybe a dumb question but that rule wouldn't match https://domain1.com/* nor would it match http://domain1.com/* just making sure that wasn't what you were trying right?
OK, i will try this first 🤞
I used the above doc and saved these configurations, still not working, I can access both URLs/domains separately
make sure your old configuration is disabled and the new one is enabled (Deployed and toggle switched on)
also just to be sure that this redirect rule is set up on your domain1.com (not domain2.com), domain1.com is on Cloudflare, and domain1.com and www.domain1.com both have at least a placeholder A record with Cloudflare proxy enabled
can you let me know what error message you get?
like define 'not working'
both domains are of hostinger, I just changed NS cloudflare
and no A records for the domain1.com
that is why you're having issues
I can access domain1.com and domain2.com separately
Ohh, so what would work in that case?
domain1.com shouldn't work at all without A records
you want domain1.com and www.domain1.com to redirect to domain2.com right?
yes
go on the Cloudflare DNS page for domain1.com
add 2 A records both pointing to
192.0.2.0
for domain1.com and www.domain1.com
(this IP is a placeholder IP mentioned in the documentation here: https://developers.cloudflare.com/dns/troubleshooting/faq/#what-ip-should-i-use-for-parked-domain--redirect-only--originless-setup )Cloudflare Docs
General FAQ · Cloudflare DNS docs
Yes. Cloudflare offers free DNS services to customers in all plans. Note that:
make sure the Cloudflare proxy is enabled for both of these (orange cloud)
For "When incoming requests match..." change "operator to "is in" and in Value add www.domain1.com (it should include both domain1.com and www.domain1.com)
I can't add A records because for @ and www, CNAME records already exists, which are of hostinger as I am using hostinger builder website
You have to pick 1, do you want domain1.com to point to your hostinger site or do you want Cloudflare to redirect it to domain2.com?
Hmm, I understand, thanks for the help, I need to read more about this to understand what would be best approach
I will update you,
again thanks for the help
No problem