Forcing the "www" in front of domain name

Hello, I currently have TWO domain names redirecting to one website.

So, for instance, “” is the main URL.

Now, if someone types in “” it will show the “” contents but still keep the “” URL intact in their browser window, which is want I want.

But, I want to force the “www.” in front of these URLs. I am using this code but there is a problem:

RewriteCond %{HTTP_HOST} !^www\.mysite1\.com$ [NC]
RewriteRule .?{REQUEST_URI} [R=301,L]

The problem is whenever someone types in “” it will show the “” URL in the browser window and will not keep the “” URL intact. Is there anyway around this?

Thanks for your help!

ComposerRyan nice.
It`s works.

I just tried that after reading your suggestion and unfortunately it did not seem to make a difference or add the “www.” in front of the name for some reason. Not sure why…

Do you have a Cpanel with your hosting?
If so then simply go to the hosting control panel and use the redirect option.

Probably the easiest way to do it without code.

Just found a code that seems to be working:

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

So far, so good. And you do not even have to specify the domain name in the code. Just copy into your .htaccess file and it seems to work.