Redirect from non-www to www and Vice-versa in your Joomla website

If your Joomla website is accessible with and without a www prefix you will have an issue with duplicate URL’s. Google will see both versions of your pages as multiple website instance of the same content and they might penalize your site for it.

Here is the code that you should add to your .htaccess file (you will find it in root folder of Joomla)

non-www to www redirect

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

www to non-www redirect:

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