Jump to content

www redirect to non-www (apex) domain


infantex

Recommended Posts

Hello.

My site is hosted in a VPS, previously it was hosted in Tommy.

Back when it was in Tommy, I could get to the site either by typing: "www.infantex.com.mx", or: "infantex.com.mx".

Now, if I type: "infantex.com.mx", I can get to the site, but, if I type: "www.infantex.com.mx", i just get a: "Success! Your new web server is ready to use" page.

My VPS was configured with Hestia CP, so I guess the success page is a default Nginx page.

My DNS is setup in Cloudflare. I have an A record "www" pointing to my VPS's IP.

From some evidence, I presume that previously, in Tommy, the "www" record was a CNAME one (I have an infantex.mx site still in Tommy and its www record is a CNAME record, so I'm extrapolating).

However, I changed the www record from A to CNAME and pointed it to the root domain (infantex.com.mx) but it's still not working (after some hours after the change).

Googling, I found that setting "Use always HTTPS" on in Cloudflare should correct this. Still no luck.

I also found several script recommendations to solve this, not really a consensus. I don't know which file the script modifications refer to or where the files are/should be located (practically zero Linux or Sys Admin experience here). Also, I never did anything remotely like that when the site was hosted in Tommy (I would remember), it just worked.

I checked the Hestia UI and found the Nginx configuration page. There are two versions: Basic and Advanced. In Basic, there's no evident option for www to non-www redirection. In Advanced, I can see the /etc/nginx/nginx.conf file, but don't know how to begin modifying it.

For example, one of the recommendations is to set different servers for www.infantex.com.mx and infantex.com.mx, like:

server {
	server_name www.infantex.com.mx;
        return 301 ...
        }
        
server {
	server_name infantex.com.mx;
        # real configuration goes here...
        }

But the /etc/nginx/nginx.conf I see in Hestia CP has not a single server section (?). I can see there's an events and an http section. I could bracket everything in the file into a server{} and add another server{} with the return 301 but I wouldn't know what I would be doing and I'm more likely to break what's working.

image.thumb.png.ddb3df11de15015ac8f7400ecb85e623.png

What should I do? Is it a question of DNS? Is it a question of Nginx configuration? Is it a matter of Hestia configuration? Something else?

Regards,

Link to comment
Share on other sites

Your HTTP, www URL redirects to the HTTPS version which is expected:

lucas@grover:~$ curl http://www.infantex.com.mx -I
HTTP/1.1 301 Moved Permanently
Date: Wed, 22 Sep 2021 23:24:23 GMT
Connection: keep-alive
Cache-Control: max-age=3600
Expires: Thu, 23 Sep 2021 00:24:23 GMT
Location: https://www.infantex.com.mx/

But then the HTTPS version redirects back to the HTTP:

lucas@grover:~$ curl https://www.infantex.com.mx -I
HTTP/2 301
date: Wed, 22 Sep 2021 23:24:23 GMT
content-type: text/html
location: http://www.infantex.com.mx/

So it might be some option in Hestia that has not been turned on (or maybe has been turned on) that is looping. I'm not sure though since I don't Hestia.

 

As for the A vs CNAME, I have my domain setup with a CNAME so that I don't have to do any extra configuration on the web server to redirect www -> root.

Link to comment
Share on other sites

Thanks for your answer.

It got me thinking... I initially used Hestia's DNS to setup my site, but some DNS records were not propagating even after several days (I don't remember if it was the SPF record or another one).

I switched over to Cloudflare for DNS and the issue was resolved.

However, the DNS zone is still set up in Hestia. I have not noticed any problems so far, but I don't know if this could cause the looping issue you see. I just deleted the www A record in Hestia, nothing changed in the curl output but it may be cached, will wait 'till tomorrow.

I would ask you if it would be OK to completely delete the DNS zone in Hestia, but you already said you're not familiar with it.  🙂  Although Hestia should be just an interface to whatever service is providing the DNS.

Link to comment
Share on other sites

40 minutes ago, infantex said:

I would ask you if it would be OK to completely delete the DNS zone in Hestia, but you already said you're not familiar with it.  🙂  Although Hestia should be just an interface to whatever service is providing the DNS.

I would imagine if you were using Cloudflare for DNS, Hestia DNS records would no longer be of any use (if I am correctly assuming it works like cPanel).

Link to comment
Share on other sites

15 hours ago, lucash said:

I would imagine if you were using Cloudflare for DNS, Hestia DNS records would no longer be of any use

I would think the same, but I can't think of anything else that'd be causing this.

I went ahead and deleted the DNS zone in Hestia. Now, www.infantex.com.mx, instead of displaying the "Success! Web server is ready" page, I'm getting a too many redirects error (ERR_TOO_MANY_REDIRECTS).

The curl output is similar to what you got: http points to https and https points to http. I don't know what's causing this or how to track who is redirectig what.  😞

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...