Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 ??

share|improve this question

migrated from stackoverflow.com May 25 '11 at 13:41

This question came from our site for professional and enthusiast programmers.

2 Answers 2

up vote 2 down vote accepted

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.

share|improve this answer

Basically they are two different things. DNS (the service which translate human readable addresses like "mydomain.com" into IP address like "") 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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.