Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have search through Google and found 2 methods to add www before domain name. First is by adding a CNAME and second is using rewrite mod in .htaccess file.

I just want to know which method is better to use or there is other method because I'm currently using standalone WordPress as my back end.

share|improve this question

migrated from stackoverflow.com Nov 20 '11 at 0:51

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

1  
Adding a CNAME will not create a redirection from domain.com to www.domain.com. Anyway, the .htaccess method is usually fine – Pekka 웃 Oct 31 '11 at 14:42
up vote 8 down vote accepted

You need both - the CNAME is a DNS record that points www.example.com to example.com's server so that if a browser tries to open www.example.com then it can find what server (IP address) it is stored on. The second is a rule on the server that says "if someone loads example.com, tell them that they should have loaded www.example.com"

share|improve this answer

not only with CNAME records, but also you can put .htaccess code for redirection:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
</IfModule>

This is a 301 redirect (which is permanent redirect.) After a few weeks the site will be visible with www in Google Search from that time.

share|improve this answer
1  
The question is possibly a bit ambiguous, as it doesn't specifically mention redirects, but anyway... as mentioned in the other answer, you still need a CNAME record as otherwise the www subdomain won't be available. Although this is a bit academic as it is nearly always setup automatically as part of the hosting account setup. – w3dk Jan 24 '13 at 15:13

Your Answer

 
discard

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