1

now days I create two files one for example.com and one for www.example.com because the wild card *.example.com doesn't work right for accessing example.com my question is how do I make example.com redirect to www.example.com using apache and not something like php. So I can have one virtual host configuration per domain.

1 Answer 1

1

Use:

SeverName example.com
ServerAlias www.example.com

in your virtual host configuration...

Then you can redirect non-www to www with something like:

<IfModule mod_rewrite.c>
  RewriteCond %{HTTPS} !=on
  RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
  RewriteCond %{HTTP_HOST} (.+)$ [NC]
  RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
</IfModule>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .