Why website with www works, but without www does not work?
I have a website hosted on commercial G-Suite Google Sites where www version of website works properly, however, the non-www version does not work properly:
# wget www.fashioncodebeautysalon.com
--2018-02-22 21:43:15-- http://www.fashioncodebeautysalon.com/
Resolving www.fashioncodebeautysalon.com (www.fashioncodebeautysalon.com)... 172.217.6.51
Connecting to www.fashioncodebeautysalon.com (www.fashioncodebeautysalon.com)|172.217.6.51|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: ‘index.html’
index.html [ <=> ] 19.78K --.-KB/s in 0.03s
2018-02-22 21:43:16 (671 KB/s) - ‘index.html’ saved [20257]
# wget fashioncodebeautysalon.com
--2018-02-22 21:43:20-- http://fashioncodebeautysalon.com/
Resolving fashioncodebeautysalon.com (fashioncodebeautysalon.com)... 216.58.195.83
Connecting to fashioncodebeautysalon.com (fashioncodebeautysalon.com)|216.58.195.83|:80... connected.
HTTP request sent, awaiting response... 404 Not Found
2018-02-22 21:43:20 ERROR 404: Not Found.
To get into this state, in the GoDaddy console I simply created DNS A record and copied IP address that I got when accessing www version of website. Is this correct way to create DNS A record, because I don't know if Google guarantees that this particular IP address will remain constant over time? Is there some other specific IP address that I should have put instead?
Since I am getting 404, then I am inclined to think that problem is not with DNS, but rather with Google Sites where their web server expects the "Host:" value in HTTP request header to have the "www" prefix. However, I am unable to add such address mapping in Google Sites console because subdomain field must not be left blank as seen here:
What am I missing here?
Adding redirect rule from domain.com to www.domain.com in GoDaddy control panel should work. What about your visitors, getting 301 redirect first time they visit your site, it will be cached in their browser. 301 is a permanent redirect code, as opposite to 302 which will not be cached and redirected each time. Which one to use it's up to you.