I'm attempting to host multiple different rails applications on a single VPS using multiple domain names. I'm using Apache 2.2.17 on Ubuntu 10.10. For Apache, I've multiple vhost files to ensure that I'm able to enable and disable particular sites easily without requiring to comment them out or remove them. Additionally, I'm also using mod_rewrite to ensure that the multiple domain names that visit the same rails application appear to visit exactly the same URL and so i do not take a success with search engines like google so far as duplicate content.

In my opinion that my DNS is setup correctly. For each one of the domain names, I've got a www subdomain in addition to some site-specific sub-domain names, for example blogs, etc. The problem I'm seeing is the fact that Apache seems to matching the www subdomain immediately and never analyzing the extra URL behind it. Altering ServerAlias does nothing. For instance, using my setup, basically enter davidheartsrachel.com, I correctly achieve my wedding website. However, basically use www.davidheartsrachel.com, I achieve my other website, my software development business. The URL isn't re-written it stays as davidheartsrachel.com rather than afewguyscoding.com.

The only method I've been in a position to correctly get results is by using mod_rewrite however vhost file to redirect towards the wedding website vhost file (you can observe which i obtain that however vhost file, but it's said out for reasons of the question). This does not appear proper in my experience? Must I get another IP and do IP vhosts rather than title-based vhosts?

After I execute apachectl -S, I recieve the next:

VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80                   is a NameVirtualHost
         default server afewguyscoding.com (/etc/apache2/sites-enabled/afewguyscoding.com:1)
         port 80 namevhost afewguyscoding.com (/etc/apache2/sites-enabled/afewguyscoding.com:1)
         port 80 namevhost blog.afewguyscoding.com (/etc/apache2/sites-enabled/afewguyscoding.com:69)
         port 80 namevhost lbbs.afewguyscoding.com (/etc/apache2/sites-enabled/afewguyscoding.com:84)
         port 80 namevhost davidheartsrachel.com (/etc/apache2/sites-enabled/davidheartsrachel.com:1)
         port 80 namevhost dhr.afewguyscoding.com (/etc/apache2/sites-enabled/davidheartsrachel_staging:1)
Syntax OK

I observe that afewguyscoding.com may be the default site - however, does not it need to perform a full string match to look for the proper site?

Primary site's vhost file

<VirtualHost *:80>
  ServerAdmin david.stites@afewguyscoding.com
  ServerName afewguyscoding.com
  ServerAlias davidstites.com, 5280software.com, milehigh-software.com, milehighsoftware.org
  ServerAlias www.5280software.com, www.milehigh-software.com, www.milehighsoftware.org, www.davidstites.com, www.afewguyscoding.com

  # this tells rails that it will run in production mode
  # this is for rails < 3.x
  RailsEnv production

  DocumentRoot /var/www/afewguyscoding/current/public
  DirectoryIndex index.html

  # custom log file locations
  # possible values include: debug, info, notice, warn, error, crit,
  # alert, emerg.
  LogLevel alert
  ErrorLog  /var/www/afewguyscoding/current/log/error.log
  CustomLog /var/www/afewguyscoding/current/log/access.log combined

  # allows compression of text based mime.types
  AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript text/css application/x-javascript
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

  FileETag None
  RewriteEngine On

  # check for maintenance file and redirect all requests
  RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
  RewriteCond %{REQUEST_URI} !\.(css|jpg|png|gif)$
  RewriteCond %{REQUEST_URI} !^/ws/
  RewriteCond %{SCRIPT_FILENAME} !maintenance.html
  RewriteRule ^.*$ /system/maintenance.html

  #RewriteCond %{HTTP_HOST} ^www.davidheartsrachel.com$
  #RewriteRule ^(.*)$ http://davidheartsrachel.com$1 [L]

  RewriteCond %{HTTP_HOST} ^www.davidstites.com$
  RewriteRule ^(.*)$ http://www.afewguyscoding.com$1 [R=301,L]

  <Directory /var/www/afewguyscoding/current/public>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
  </Directory>

  # In case I ever need CGI
  #ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  #<Directory "/usr/lib/cgi-bin">
  #     AllowOverride None
  #     Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  #     Order allow,deny
  #     Allow from all
  #</Directory>

  # how we can restrict access to documents from the local subnet
  #Order deny,allow
  #Deny from all
  #Allow from 127.0.0.0/255.0.0.0 ::1/128

  <Location /blog>
    PassengerEnabled off
  </Location>
</VirtualHost>

<VirtualHost *:80>
  ServerAdmin info@afewguyscoding.com
  ServerName blog.afewguyscoding.com

  DocumentRoot /var/www/wpress
  DirectoryIndex index.php

  <Directory /var/www/afewguyscoding/current/public>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
  </Directory>
</VirtualHost>

Wedding site's vhost file

<VirtualHost *:80>
  ServerAdmin info@davidheartsrachel.com
  ServerName davidheartsrachel.com
  ServerAlias rachelanddavid.net, rachelanddavidstites.com, rachelanddavidwedding.com
  ServerAlias www.davidheartsrachel.com, www.rachelanddavidstites.com, www.rachelanddavidwedding.com, www.rachelanddavid.net

  # this tells rails that it will run in production mode
  # this is for rails < 3.x
  RailsEnv production
  # this is for rails >= 3.x
  RackEnv production

  DocumentRoot /var/www/davidheartsrachel/current/public
  DirectoryIndex index.html

  # Custom log file locations
  # Possible values include: debug, info, notice, warn, error, crit, alert and emerg,
  LogLevel alert
  ErrorLog  /var/www/davidheartsrachel/current/log/error.log
  CustomLog /var/www/davidheartsrachel/current/log/access.log combined

  # Allows compression of text based mime types
  AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript text/css application/x-javascript
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

  FileETag None
  RewriteEngine On

  # Check for maintenance file and redirect all requests
  RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
  RewriteCond %{REQUEST_URI} !\.(css|jpg|png|gif)$
  RewriteCond %{SCRIPT_FILENAME} !maintenance.html
  RewriteRule ^.*$ /system/maintenance.html [L]

  RewriteCond %{HTTP_HOST} ^www.rachelanddavidwedding.com$
  RewriteRule ^(.*)$ http://www.davidheartsrachel.com$1 [R=301,L]

  RewriteCond %{HTTP_HOST} ^www.rachelanddavidstites.com$
  RewriteRule ^(.*)$ http://www.davidheartsrachel.com$1 [R=301,L]

  # Static cache
  RewriteCond %{REQUEST_METHOD} !^POST$
  RewriteCond /var/www/davidheartsrachel/current/tmp/cache/static$1/index.html -f
  RewriteRule ^(.*)$ /var/www/davidheartsrachel/current/tmp/cache/static$1/index.html [L]

  <Directory /var/www/davidheartsrachel/current/public>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    Allow from All
  </Directory>
</VirtualHost>

If you're able to think about anymore information that could be useful, please, request me to publish it.

Edit:

Allow me to attempt to obvious this up. Within the most important form, my real question is: how come likely to davidheartsrachel.com goes to www.afewguyscoding.com and davidheartsrachel.com goes to davidheartsrachel.com according to my configuration above