My clients want to use 301 redirects to force the www subdomain on their sites. So, "example.com/something" resolves to "www.example.com/somthing", etc.
What I'm trying to do is just add this to my vhost file:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName example.com
ServerAlias www.*
DocumentRoot /data/apps/example.com/current/public
RailsBaseURI /
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule ^ http://www.example.com%{REQUEST_URI} [L,R=301]
</VirtualHost>
I also ensured that mod rewrite was enabled with:
sudo a2enmod rewrite
sudo /etc/init.d/apache2 force-reload
. Apache . . "www.example.com", "example.com" . "www.example.com", . ? apache , . , vhost .htaccess?
. .