There are two major considerations here: DNS, and virtual host configuration.
DNS is the system by which computers resolve names to IP addresses to determine which network computer a name refers to. www.domain.com
is technically a subdomain of domain.com
(although it is rarely treated as such) and can resolve to a different IP address to the root of the domain. The usual approach to this is to create a CNAME (alias) record for www.domain.com
that points to domain.com
. This means that if your server's IP address changes, you only need to update the A record for the root of the domain, and www.
will follow suit. Your host/domain registrar should have provided you with a control panel that will allow you to modify the DNS records for your domain - if they have not, or you are unsure how to do this, you should contact your hosting company for assistance.
Virtual Hosting is a system that allows one server to be responsible for services provided by more than one domain. Shared hosting environments use this kind of system. In order for it to work, the server needs to be told which domains it is responsible for. The approaches to this are many and varied, but the key point is that since the root of the domain and www.
are technically different, the server will need to be told that they actually refer to the same resource. This would likely be the responsibility of your hosting company to ensure that the proper configuration is in place, and if your DNS is properly configured but you are still having a problem, you should contact them to have them check the configuration.