How to always redirect to "www" or "non-www"

We will force all browser access from http://mydomain.com to http://www.mydomain.com.with the help of modifying the.htasccess-file

Open your .htaccess file which is located in the root folder of your joomla-installation (make sure it is renamed from htaccess.txt to .htaccess!) than add:

non-www > www

########## Begin - Redirect non-www to www
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
## If the above throws an HTTP 500 error, swap [R=301,L] with [R,L]
########## End - Redirect non-www to www

www > non-www

########## Begin - Redirect www to non-www
## WARNING: Comment out the non-www to www rule if you choose to use this
# RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
# RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
## If the above throws an HTTP 500 error, swap [R=301,L] with [R,L]
########## End - Redirect non-www to www