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

http://akenterprisesroofing.ca

I do have some code in the .htaccess file now and it does redirect http://www.akenterprisesroofing.ca to the shorter version www.akenterprisesroofing.ca

I want to know how to also include the redirect to get http://akenterprisesroofing.ca to the URL www.akenterprisesroofing.ca 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

fadercreepAsked:
Who is Participating?

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

x
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 http://www.akenterprisesroofing.ca/index.html to the short version www.akenterprisesroofing.ca

just need it to go the other way? Any Thoughts on how to get akenterprisesroofing.ca to redirect to www.akenterprisesroofing.ca
0
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 ^(.*)$ http://www.akenterprisesroofing.ca/$1 [R=permanent,L]

Open in new window

0
Steve BinkCommented:
Your question is a little confusing - you state that the "short" version is "www.akenterprisesroofing.ca", 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 ^/?(.*)$ http://www.akenterprisesroofing.ca/$1 [R=permanent,L]

Open in new window

0
arnoldCommented:
What is the difference that you are seeing?
How is the VirtualHost entry setup, is it setup with the servername as www.akenterprisesroofing.com with a serveralias as akenterprisesroofing.com?
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.
0
InsoftserviceCommented:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
0

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.