I am attempting to pressure www for my website address with .htaccess:

RewriteCond %{HTTP_HOST} ^mysite\.com$ [NC]
RewriteRule ^(.*)$ http://www.mysite.coml/$1 [R=301,L]

Basically open mysite.com this working ok - it adds www. It might be http://www.mysite.com/index.php.

But when I open mysite.com/subpage I rerouted to http://www.mysite.com/index.php again, rather than http://www.mysite.com/subpage.

But when I open http://www.mysite.com/subpage I do not get redirect (the expected behavior).

How do i fix this? I'd like the redirect all demands to my website towards the www subdomain.

In the superb HTML5 Boilerplate .htaccess:

<IfModule mod_rewrite.c>
  RewriteCond %{HTTPS} !=on
  RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
  RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>

The issue is the following:

RewriteCond %{HTTP_HOST} ^mysite\.com$ [NC]

^ identifies the start of the string while $ identifies the finish.

To be able to have great results you must have a wildcard choose following the .com or .+.

to reiterate what Alex stated:

 <IfModule mod_rewrite.c>
   RewriteCond %{HTTPS} !=on
   RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
   RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
 </IfModule>