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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Web Server

From novice to tech pro — start learning today.