Redirect non-www to www in .htaccess

I have this in my .htaccess file:

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

but whenever I access a file on my root like http://example.com/robots.txt it will redirect to http://www.example.comrobots.txt/.

How can I correct this so that it will redirect correctly to http://www.example.com/robots.txt?

13 Answers
13

Leave a Comment