The www prefix has not bearing on search engine rank on it’s own. Keep in my that to a search engine, http://www.example.com and example.com may be two different sites. So if you’re already indexed with the www, then you can use the following rules, otherwise it really makes no difference in terms of SEO, more of a personal preference for the webmaster I suppose.
This rule should add the www prefix:
RewriteRule ^(.*) http://www.YOURDOMAIN.EXT [L,R=301]
and this one should add the trailing slash:
# If requested resource does not exist as a file
RewriteCond %{REQUEST_FILENAME} !-f
# and does not end with a period followed by a filetype
RewriteCond %{REQUEST_URI} !..+$
# and does not end with a slash
RewriteCond %{REQUEST_URI} !/$
# then add a trailing slash and redirect
RewriteRule (.*) $1/ [R=301,L]
Good luck,
Michael.
Thread Starter
bazil
(@bazil)
you had stated:
“and this one should add the trailing slash:”
is there an advantage to the trailing slash?
I don’t think there is any specific technical advantage to it, though I may be wrong, it just keeps everything neat and tidy. I’m especially retentive on trivial details like that, so I always force the trailing slash.
In terms of SEO, I have read that it is ‘better’ to have no file extensions, so if you change structure or SSSL’s (ie say ASP to PHP), the extensionless URI is still the correct one. Just keep things consistent, as long as the search bot can get to the page, then it’s happy.
Cheers,
Michael.
Hi niziol –
Thanks for the great post, for someone like me who doesn’t understand what’s going on with .htaccess it’s great for someone to spell it out for me 🙂
One question, though… If 2 people link to my site, one to http://www.mydomain.com and one to http://www.mydomain.com/, will google see these as two separate sites or does the redirect tell google to see them as the same site?
thanks,
guy