Forum Moderators: phranque
My question is: is it possible to redirect non www domains to www domains without writing a rule for every domain name on the server?
For example, example1.com, example2.net, and example3.org needs to be redirected to www.example1.com, www.example2.net, and www.example3.org respectivly, but hopefully without the need to write a rule each.
So, in the above example, when a new domain name is registered: example4.info it automatically gets redirected to www.example4.info.
After searching the internet and these forums, I believe that something like this would work:
RewriteEngine on
RewriteCond %{HTTP_HOST}!^(www\.*\.*) [NC]
RewriteRule (.+) http://www.*.*/$1 [R=301,L]
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(.+)\.com [NC]
RewriteRule (.*) http://www.%1.com/$1 [R=301,L]
Jim