Redirect non-www to www in .htaccess

Doing some Rewrites in the .htaccess file for a website that I am actively doing SEO on. I want to ensure I have just one version indexed in Google and it seems like all of my backlinks are pointed to

I do have some code in the .htaccess file now and it does redirect to the shorter version

I want to know how to also include the redirect to get to the URL as well.

this is my code

RewriteEngine On
RewriteRule ^index\.html$ / [R=301,L]
RewriteRule ^(.*)/index\.html$ /$1/ [R=301,L]

Open in new window

Who is Participating?
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
fadercreepAuthor Commented:
Also the above code redirects to the short version

just need it to go the other way? Any Thoughts on how to get to redirect to
fadercreepAuthor Commented:
Also tried this code with the same result.. is there any other place where I can miss setting this?

Options +FollowSymLinks RewriteEngine on
RewriteCond %{HTTP_HOST} ^akenterprisesroofing\.ca
RewriteRule ^(.*)$$1 [R=permanent,L]

Open in new window

Steve BinkCommented:
Your question is a little confusing - you state that the "short" version is "", and you want to redirect from the same URL.  

The last bit of code you posted is almost what you need.  Below is a minor edit, but it should otherwise work.  If it is still not redirecting, turn on your RewriteLog and post an excerpt showing what is happening.
Options +FollowSymLinks 
RewriteEngine on
RewriteCond %{HTTP_HOST} ^akenterprisesroofing\.ca
RewriteRule ^/?(.*)$$1 [R=permanent,L]

Open in new window

What is the difference that you are seeing?
How is the VirtualHost entry setup, is it setup with the servername as with a serveralias as
if it is not, i.e. it is setup in the opposite order, change the references as suggested above and see whether that achieves what you want.

The redirect is unnecessary and resource wasting.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.