1

I recently purchased a hosting plan from one of the service providers. They offered a free domain-name to me and I gladly purchased it.

Now I logged into their control panel and put all my files there and then my site became online and is working fine.

I observed yesterday that when I hit www.domain-name.com or domain-name.com, the site displays correctly. But I had thought that when I hit domain-name.com, it will get redirected to www.domain-name.com which is not happening. Also I read in internet wherein some people say the two are different.

I am really confused regarding this. Are www.domain-name.com and domain-name.com different? If yes, how do I set up a redirect such that all domain-name.com requests redirect to www.domain-name.com?

I also want to know where do I setup the redirection ??

2 Answers2

2

The www subdomain is the historical subdomain for the webserver (in contrast to mail.domain-name.com for example). But today its rather confusing. The initiative no-www.org is even suggesting to drop it.

So they suggest to redirect the other way around, from www.domain-name.com to domain-name.com. If you have an Apache webserver, you can do it like this:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L] 

This can be done in the Apache configuration file or in a local .htaccess file, whatever is possible in your provider's environment.

1

Basically they are two different things. DNS (the service which translate human readable addresses like "mydomain.com" into IP address like "1.2.3.4") sees www.mydomain.com and mydomain.com as two different things. When a request for the particular address is sent to a DNS server, it will provide the IP address that it refers to. Since in this case its the same server, it gets handled by the .htaccess as shown above. Otherwise you would have to create DNS name pointers (called A-Records) which associate the given URL to a particular IP address.

Matthew
  • 2,737
  • 8
  • 35
  • 51