2

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.

1
  • 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, 2011 at 14:42

2 Answers 2

8

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"

0
1

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.

1
  • 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.
    – MrWhite
    Jan 24, 2013 at 15:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.