I'm trying to force www
for my site address with .htaccess
:
RewriteCond %{HTTP_HOST} ^mysite\.com$ [NC]
RewriteRule ^(.*)$ http://www.mysite.coml/$1 [R=301,L]
If I open mysite.com
this working ok - it adds www
. It becomes http://www.mysite.com/index.php
.
But if I open mysite.com/subpage
I redirected to http://www.mysite.com/index.php
again, instead of http://www.mysite.com/subpage
.
But if I open http://www.mysite.com/subpage
I don't get redirect (which is the expected behaviour).
How can I fix this? I would like the redirect all requests to my site to the www
subdomain.
From 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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With