It may be simplistic, but I do this with a second VirtualHost.

<VirtualHost *>
ServerName www.mydomain.com
DocumentRoot /foo/bar
</VirtualHost>

<VirtualHost *>
ServerName mydomain.com
Redirect / http://www.mydomain.com/
</VirtualHost>

Since my SSL certificate is configured only for the www version of my URL, I
have to make sure that no matter which URL they use to enter the site, they
are immediately redirected to the www version of that URL. Including the /
on the end of the Redirect domain allows my server to also handle requests
directly to subpages & subdirectories with the non-www address, ensuring
that those URL are rewritten as well. But this can become tedious if you
have a large number of URLs that you need to do this for. 

-----Original Message-----
From: Bob Ionescu [mailto:bobsie...@googlemail.com] 
Sent: Friday, January 09, 2009 6:34 AM
To: users@httpd.apache.org
Subject: Re: [us...@httpd] rewrite rule ideas needed..

2009/1/9 Anders Norrbring <li...@norrbring.se>:
> But how can I create a setup that will simple add www to any of the valid
> ServerAlias names listed in the virtual host?  They shall keep the domain
> name part as is, and not rewrite to one name only.

Have a look at the last example of the section "Canonical Hostnames":
http://httpd.apache.org/docs/trunk/rewrite/rewrite_guide.html#canonicalhost

But make sure, you're sending a 301 redirect (R=301) for search engines.

Bob

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscr...@httpd.apache.org
   "   from the digest: users-digest-unsubscr...@httpd.apache.org
For additional commands, e-mail: users-h...@httpd.apache.org


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscr...@httpd.apache.org
   "   from the digest: users-digest-unsubscr...@httpd.apache.org
For additional commands, e-mail: users-h...@httpd.apache.org

Reply via email to