I'm using the configuration below to use vhost_alias_module to more easily manage my hosted setup. I want sites to be structured like the following /sites/domain.com/w/w/w/ which with the configuration below works fine. However, if I attempt to access domain.com instead of www.domain.com this falls apart. How do I fix this?
Update: I want request for domain.com to automatically be directed to www.domain.com. It would be fine if this required a 403 redirect (I think that would be preferred from a SEO perspective) .
LoadModule vhost_alias_module /usr/lib/apache2/modules/mod_vhost_alias.so
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /sites/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /sites/>;
Options Indexes FollowSymLinks MultiViews ExecCGI
AllowOverride All
Order allow,deny
allow from all
</Directory>
UseCanonicalName Off
VirtualDocumentRoot /sites/%2+/%1.1/%1.2/%1.3+
</VirtualHost>
Well, the requirement to imply
www
comes close to pushing you out of being able to use mod_vhost_alias, and into mod_rewrite territory.. but there's a couple options that I can think of:Just redirect to
www
.Let those requests work without a redirect, and use symlink trickery to stick them to the www location.
With your
VirtualDocumentRoot
, requests todomain.com
go to/sites/com/d/o/m
- let's change that:This will make a request for
domain.com
go to/sites/domain.com/_/_/_
- make this location a symlink to/sites/domain.com/w/w/w
.