Do I need a 301 redirect on htaccess if Apache is already configured to serve?
-
Apache is set up to serve both www and non-www versions the same content. Do I still need to put a 301 redirect in the htaccess file?
-
It's best practice to only serve a particular site one way or the other, either www or non-www, and only have one URL available for the homepage. This prevents any related duplicate content issues, and ensures you always get backlinks back to the right domain. I'd definitely recommend you add a rewrite rule to your .htaccess, using one of the following examples.
removes www
RewriteCond %{HTTP_HOST} ^www.yourdomain.com [NC]
RewriteRule ^(.*) http://yourdomain.com/$1 [L,R=301]
adds www
RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]
-
But if it's Apache and set up to display the same content no matter which - how do I know which of the codes to add?
-
If you're launching the site fresh, just pick one and stick with it. If you've got an existing site, see which version Google returns in the SERPs, and use that.
-
It's using www. in the SERPs. Does that mean I need to use the "## adds www"?
Thanks!
-
Yes, in that case, use the code that adds www. Then anyone who links to or attempts to visit the non-www, will be 301 redirected to the www version.