Www and non-www domain pointing to different IPs despite DNS being correct? How to redirect www

a-recordcname-recorddomain-name-systemredirect

I'm having an issue where our non-www domain is currently pointing to the correct IP, but our www is pointing to a random IP address that belongs to our host. So when we visit the www domain, it does to the login screen for Hostmonster instead of our website. I want the www to redirect to the non-www.

First we pointed the A record for the www to the same IP as our non-www domain. I waited over 12 hours and it wouldn't propagate so I contacted CS and they repushed it. Still, nothing happened.

So this time around they tried to put it in as a CNAME instead. So now the www is pointed to our non-www domain as a CNAME. Apparently the representative also added a redirect code to our htaccess (but not 100% sure on this). It's been hours and it doesn't look to have propagated either.

We've been struggling with this issue for days. Our host has been not much help so far. They are just as confused as we are. First they said it might be an issue with their server migration, then they tried changing the DNS as described above to no avail.

Normally this would be an easy process, but I'm quite frustrated at this point because visitors are thinking our website doesn't work when it's only the www that doesn't work.

I also tried private browsing, cleared my browser cache, and tried multiple devices.

Any hints on what could be the issue? Thank you.

Best Answer

To me, it looks like a problem with your DNS management provider. Try changing your nameservers from your current DNS provider to someone's else where you can manage your records by yourself (Cloudflare would be a good option as it is free) and then point your domains with www and non-www from there (make sure to enable proxy on Cloudflare as they map your current IP with their own IP).

Other than that, check your web server configuration files (sites-enabled for nginx and apache). Make sure that your domain with www is present inside these configuration files. If your web server is nginx, then you can find your domain names inside Server block with the server_name directive and if it is Apache, then you can find it inside Virtual host block with ServerName directive.

Also, if you are using some sort of caching server (like varnish) try to purge its cache. Remove any unnecessary redirections inside your .htaccess file and only keep the force non-www redirection rule (attached below) inside it and see if it works.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]

Hope that helps!

Related Topic