htaccess将参数传递给索引并重定向到www

I have this on my .htaccess file and I want add a rule to redirect my site from non-www to www.

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

you can try this

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)index.php$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

I used the code below to redirect my non-www URL to a www one. I added it on my .htaccess file and it works just fine. I hope this code can help you. Just replace the domain name with your own domain name. Good luck.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomainname.com [NC] 
RewriteRule ^(.*)$ http://www.yourdomainname.com/$1 [L,R=301] 
RewriteCond %{THE_REQUEST} ^(.*)index.php
RewriteRule ^(.*)index.php$ http://www.yourdomainname.com/$1 [R=301,L]