Introduction

Have you ever checked if your site can be visited at both links: http://yoursite.com AND http://www.yoursite.com If not, try it, I recommend that you try it now.

Some search engines may view site.com and www.site.com as being two different URLs. If you split your link popularity amongst both versions, you will have less authority on each version than if the two were combined.

So it is recommended that you pick one style and stick with it

Redirection

To do the redirection, add the code below to your .htaccess (right below the RewriteBase line)

Don't forget to change example.com to your domain name

From non-www to www

# Fix trailing slash
# If URL-path does not contain a period or end with a slash
# RewriteCond %{REQUEST_URI} !(\.|/$)
# add a trailing slash
# RewriteRule (.*) http://www.example.com/$1/ [R=301,L]
#
# Domain canonicalisation
# Redirect all non-www domain requests, and www with port number, to www domain
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

From www to non-www

# Fix trailing slash
# If URL-path does not contain a period or end with a slash
# RewriteCond %{REQUEST_URI} !(\.|/$)
# add a trailing slash
# RewriteRule (.*) http://example.com%{REQUEST_URI}/ [R=301,L]
#
# Domain canonicalisation
# Redirect all www domain requests, and non-www with port number, to non-www domain
RewriteCond %{HTTP_HOST} !^(example\.com)?$
RewriteRule (.*) http://example.com%{REQUEST_URI} [R=301,L]
zencart/modules/ssu/for_users/www_and_nonwww.txt · Last modified: 2010/03/06 04:07 by g1smd
www.chimeric.de Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0