I have a strange DNS setting glitch here.
We are rebuilding and migrating two old sites to a new VPS server. They coexist now as below. We use Cloudflare DNS (NO reverse proxy).
Site A: aaa.example.com
(on an old server)
Site B: bbb.example.com
(same as Site A)
New Site A: aaa2.example.com
(on the new VPS built by Ubuntu 21.10 + Nginx + WordPress)
New Site B: bbb2.example.com
(same as New Site A)
Now both new sites are finished and we need to officially launch them. Here are what we did in Cloudflare DNS:
We first added an A record with name = aaa2
and IP = VPS IP
. This works fine and we could access the new site with the URL aaa2.example.com
(this is how we developed the new site).
And now we added a CNAME record with name = aaa
and target = aaa2.example.com
, and then in WordPress Dashboard we changed both WordPress Address and Site Address in Settings > General to https://aaa.example.com
. We also used a plugin called Better Search Replace to replace all strings aaa2.example.com
in the database to aaa.example.com
.
I think it’s a proper setup because this works perfectly and now the site A is fully transferred to the new site A on the VPS. We can use the official URL aaa.example.com
to access it.
As we did in 1., we added an A record bbb2
for the new site B and it just works fine.
Here comes the problem. As we did in 2., we added a CNAME record with name = bbb
and target = bbb2.example.com
, but somehow now the URL bbb.example.com
gets redirected to aaa.example.com
(new site A)! I cannot understand why this happens.
bbb2.example.com
still works (leading to new site B).
If in WordPress Dashboard we changed both WordPress Address and Site Address in Settings > General to https://bbb.example.com
or just used the plugin to replaced all strings, both bbb.example.com
and bbb2.example.com
would get redirected to aaa.example.com
. It’s the worst result because we would lose all access to the new site B and had to use the snapshot backup on the VPS to restore the whole system.
Any thoughts about how to solve this redirect error in Cloudflare DNS?
I got stuck here for over 1 month. I'm pretty sure there is no typo in the DNS records. ChatGPT told me to check these things:
Deactivate plugins that may cause this redirect: I couldn't find any plugin that could lead to this. Also these two new sites use exactly the same plugin combination.
Check the SSL certificate: the server administrator used a wildcard Certbot setting so all subdomains should be covered.
Check the Nginx settings: Unfortunately I'm not the administrator so can't access the server. I have no knowledge on Nginx anyway.