Add www to URL using Apache mod_rewrite
Submitted by amitsedai on Thu, 01/10/2013 - 22:13Technologies:
For sites belonging to a domain name(Not Subdomain), one can access the site using the domain name with www, Ex: www.example.com or without it: example.com
Both ways the site can be accessed when a ServerAlias is created in the config. However this is confusing as session information for both is different, which means if one is accessing the site with www preceded and logs in, on accessing the site without www preceded - the server would have no information saved.
To redirect any domain name to use www by default, the following mod_rewrite condition can be used: