Hi Scott,
I recommend
not doing major edits to the config files in the /etc/apache2/sites directory. These are sometimes 'auto-cleaned' of custom edits by Server Admin when editing and committing through it (very annoying). Here's what I did that works well for me and has not been auto-cleaned so far:
1) Make a dir /etc/apache2/users
2) Make new files in that dir that have names based on your server's web users, e.g.
myuser.conf (should not be system users, and not have their web directories in the /Library/Webserver area, IMHO).
3) Add *Include "/etc/apache2/users/myuser.conf"* to the end of and inside of the <VirtualHost> directive in your site config file in question from /etc/apache2/sites dir.
4) Add all your custom edits to the user file you need, in this case the 301 redirect (see below for my favorite add-www-301 redirect). If using BBEdit, make sure to re-lock the files when done, but you can leave them open.
5) In Terminal run +apachectl -t+ to make sure you have no syntax errors in your config edited files, or the Apache will crash when you try to restart it, taking your sites off-line.
5) Open /var/log/apache2/error_log, with +tail -F -n 50 /var/log/apache2/error_log+ or in Console on the server.
5) Then, in Server Admin under Web -> Sites, make a trivial change and reverse it (like checking then un-checking a box) as this allows you to gracefully restart Apache without screwing up the Webcache feature (see Web PDF docs about
not using +apachectl graceful+ ).
6) Go back to your Apache error log and make sure Apache did not crash. If it did, reverse your edits and restart Apache again.
Here is my favorite add-www-301 redirect:
<IfModule mod_rewrite.c>
RewriteEngine On
# Google canonical redirect
RewriteCond %{HTTP_HOST} ^\[^\.\]+\.....?$ \[NC\]
RewriteCond %{HTTPS} !^on$ \[NC\]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}$1 \[R=301,L\]
RewriteCond %{HTTP_HOST} ^\\[^\.\\]+\.....?$ \[NC\]
RewriteCond %{HTTPS} ^on$ \[NC\]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}$1 \[R=301,L\]
</IfModule>
As opposed to other redirects that state the name of the domain, this will cover sites that have multiple domains assigned to them and up to four letters in the TLD (like .info). Also, it handles
https redirects as well. Always adding (or removing) the www is important to keep your sites page ranking in Google from being diluted by the non www use (or use) of the base domain. You may already know this, of course.
The new book
http://buildingfindablewebsites.com/ explains this well, though its mod_rewrite solution in limited. Caveat: HTTPS part may not work well with older browsers that do not support HTTP 1.1.
Larry