force non www to www in .htaccess file

asked Jul 24, 2015 by anshul (420 points)
I know that it is out of scope question for you...
but due to automatic changes done during installation of seo toaster in .htaccess file... i am unable to figure out where to write this block of code...

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

Can you help me out ?

1 Answer

answered Jul 28, 2015 by Andrey Budchenko (3,900 points)
Hello anshul.

Default.  .htaccess file.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

RewriteRule !\.(js|ico|jpe?g|gif|png|css|pdf|avi|mov|mp(3|4|e?g)|lng|(r|t)ar|tgz|zip|swf|ttf|eot|svg|woff)$ index.php [NC,L]

Also if you want to forward all request with and without www. to www.
Change your website name in your application.ini as www.examle.com/ and use default .htaccess.

Thank you.
commented Jul 28, 2015 by anshul (420 points)
Done as said... It's working fine...
Many thanks to you Andrey...
...