htaccess mod rewrite ignoring forward slash
I've been searching and searching with no success for this simple htaccess redirect from a non-www URL to a www.
I have the following in the site's root htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
From what I've read this should work but instead of htp://domain.com/index.html going to htp://www.domain.com/index.html, it goes to htp://www.domain.comindex.html/ - Notice the ignored forward slash between .com and index.html
I have also tried the following rewrite conditions: (not all at once obviously)
RewriteCond %{HTTP_HOST} domain.com [NC]
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
Any help would be greatly appreciated.
NOTE: Domains would usually have 'http' but because of the stack overflow limit 开发者_开发问答of urls, I've had to remove a 't' :)
Tested solution that just works (at least on all my production servers):
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
精彩评论