Dumb SEO Questions

(Entry was posted by Christopher Hale on this post in the Dumb SEO Questions community on Facebook, 01/11/2015).

What code do I use for 301 redirect and where?

Newbie Question: I just started a new website lets called it www.example.com, and it`s reachable with both the non www and www versions. In GWT I have the preferred domain set to www.example.com. Do I need to do a redirect of the non www version to the www version? If so what code do I use and where? Any suggestions of a webpage that can explain this would be awesome! Thanks in advance!

Christopher?
This question begins at 00:34:23 into the clip. Did this video clip play correctly? Watch this question on YouTube commencing at 00:34:23
Video would not load
I see YouTube error message
I see static
Video clip did not start at this question

YOUR ANSWERS

Selected answers from the Dumb SEO Questions Facebook & G+ community.

  • Christopher Hale: Newbie Question: I just started a new website lets called it www.example.com, and it's reachable with both the non www and www versions. In GWT I have the preferred domain set to www.example.com. Do I need to do a redirect of the non www version to the www version? If so what code do I use and where? Any suggestions of a webpage that can explain this would be awesome! Thanks in advance!

    Christopher
  • Shaharyar Afzal: You need to use canonicalization for this purpose. Here is the code ;
    <link rel="canonical" href="http://www.example.com" />
  • Christopher Hale: Where do I put it? I use Wordpress....thanks for responding!
  • Shaharyar Afzal: This code needs to get into head tag of your website. Can i see your website?
  • promoz seo: GWT preferred domain section is built for Google only. If you are targeting search engines other than Google then you should redirect the domain to a preferred version.
    You can write this code in your .htaccess file to redirect the domain to www version.

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

    Must read: http://moz.com/blog/htaccess-file-snippets-for-seos
  • Christopher Hale: Thanks guys! 
  • Athanasios Giannias: +Shaharyar Afzal ;a 301 redirect, is this a better solution? ;
  • Shaharyar Afzal: +Athanasios Giannias​ a 301 redirect is also a better solution but you should have knowledge about .htaccess file.. Its little bit complicated for beginners 
  • Christopher Hale: I was messing around with my .htacces file and added the appropriate code to point my non www version to my www.version however when it came to reaching my wordpress admin it couldn't find it? Was I putting the code in the wrong place on the .htaccess file?
  • Tony McCreath: Not certain but I thought WordPress did the 301 redirects for you by default.

    Position in .htaccess can be very important. Make sure it is early and definitely before the WordPress section.
  • Rajeshwar Reddy: If you are using Apache server you could do that with Mod rewrite. Place this code at the beginning .htaccess file and save it in the root domain.
    RewriteCond %{HTTP_HOST} !^www. [NC]
    RewriteCond %{HTTP_HOST} !^$
    RewriteRule ^/?(.*) http://www.%{HTTP_HOST}/$1 [L,R,NE]

    http://httpd.apache.org/docs/2.2/rewrite/remapping.html

View original question in the Dumb SEO Questions community on Facebook, 01/11/2015).