Tell me more ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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

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

2 Answers

up vote 4 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
+1 beat me by 35 seconds. – Jason McCreary Oct 31 '11 at 14:43
thank you.. I got the answer really fast. :D first time using stackoverflow – nackle Oct 31 '11 at 14:46

in case you dont use CNAME records, htaccess can redirect too:

In your FTP root (maybe in public_html) should be a file called .htaccess, then open it and add this code into it (problably after the first line, bofore other rules start) .

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

( if there is not such file, then create a simple new text file with notepad and upload to the website root directory, and rename it to .htaccess )

This is 301 (which is permanent redirect), and then after a few weeks the site will be visible with www in Google search engines anymore.

share|improve this answer
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. – w3d Jan 24 at 15:13

Your Answer

 
discard

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