Hello, I want to redirect my website automatically from non-www to www domain. Here is what I have done. rewritecond %{http_host} ^example.com [nc] rewriterule ^(.*)$ http://www.example.com/$1 [r=301,nc] This works for just the url not for other pages like if I write example.com/index.htm then it doesn't redirect to http://www.example.com/index.php however it redirects example.com to http://www.example.com. but doesn't redirect the urls with the pages. How can I redirect every url of a website from non-www to www? Please help me. Thanks in advance.
what I want to say that if I type example.com in the browser then it redirects it to www.example.com but if I type example.com/index.php then it doesn't. I have tried with appending $1 in the htaccess but still its not redirecting all the pages. So, is it possible to redirect all the pages of website from non www to www?
This may work the last line is slightly different. Works for me fine RewriteEngine On RewriteCond %{HTTP_HOST} ^example.com [NC] RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301] Code (markup):