Wildcard Virtual Host in Apache2

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
User avatar
panic!
Forum Regular
Posts: 516
Joined: Mon Jul 31, 2006 7:59 am
Location: Brighton, UK

Wildcard Virtual Host in Apache2

Post by panic! »

hi guys,

What I'd like to do, is have a wildcard catch-all subdomain that will use a directory as it's DocumentRoot based on the subdomain at present I have:

Code: Select all

 
<VirtualHost *:80>
    DocumentRoot /var/www/vhosts/cats/
    ServerName  cats.darwin
</VirtualHost> 
    
    
<VirtualHost *:80>
    DocumentRoot /var/www/vhosts/dogs/
    ServerName  dogs.darwin
</VirtualHost> 
 
<VirtualHost *:80>
    DocumentRoot /var/www/vhosts/mice/
    ServerName  mice.darwin
</VirtualHost> 
 


what I'd like to do is have something like

Code: Select all

 
<VirtualHost *:80>
    DocumentRoot /var/www/vhosts/this-bit-be-matched-to-the-sub-domain/
    ServerName  *.darwin
</VirtualHost> 
 
Are there any smarty pants geniuses that know how I could do this?

Thank you all.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Re: Wildcard Virtual Host in Apache2

Post by Maugrim_The_Reaper »

Look up the VirtualDocumentRoot directive along with the mod_vhost_alias module for Apache 2.2. I'm not going to elaborate since I'm 99% certain it's explained in the Apache manual as mass virtual hosting.

If you can't get it to work using the manual and a google search then someone will be willing to dig deeper into the mechanics, but please try it yourself first ;).
User avatar
panic!
Forum Regular
Posts: 516
Joined: Mon Jul 31, 2006 7:59 am
Location: Brighton, UK

Re: Wildcard Virtual Host in Apache2

Post by panic! »

ok sweet thank you figured that out now

now I have the following which works perfectly. but the .htaccess files within each vhost are breaking and giving 'Internal Server Error'

My new, working conf

Code: Select all

 
 
 
NameVirtualHost xxx.darwin.juretic:80
 
<VirtualHost  xxx.darwin.juretic:80>
   ServerName  xxx.subdomain.domain.com
   ServerAlias *.darwin.juretic
   UseCanonicalName Off
   DocumentRoot "/var/www/vhosts/"
   VirtualDocumentRoot /var/www/vhosts/%1
    
    
    
     <Directory "var/www/vhosts/">
      Options +FollowSymLinks
      Options Includes FollowSymLinks 
      AllowOverride All
      Order allow,deny
        Allow from all
   </Directory> 
</VirtualHost>
 
my now breaking .htaccess

Code: Select all

 
 
RewriteEngine On
 
 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
 
RewriteRule ^(.+)$ index.php [L]
RewriteRule ^()$ index.php [L]
 
options -indexes
 
 

I'm guessing I need to some how prefix the Conds and Rules with the VirtualDocumentRoot's


I've tried messing around with a few things and I can't figure :(
User avatar
panic!
Forum Regular
Posts: 516
Joined: Mon Jul 31, 2006 7:59 am
Location: Brighton, UK

Re: Wildcard Virtual Host in Apache2

Post by panic! »

FIXED:

Code: Select all

 
# RewriteEngine On
#  
#  
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_FILENAME} !-d
#  
# RewriteRule ^(.+)$ /index.php [L]
# RewriteRule ^()$ /index.php [L]
#  
# options -indexes
 
added / to the start of /index.php

rad!
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: Wildcard Virtual Host in Apache2

Post by jayshields »

Have you commented out those lines or was that a pasting error? I'm pretty sure it's the latter but I'm just clearing things up :)
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Re: Wildcard Virtual Host in Apache2

Post by Maugrim_The_Reaper »

Bow down and worship me ;).
User avatar
panic!
Forum Regular
Posts: 516
Joined: Mon Jul 31, 2006 7:59 am
Location: Brighton, UK

Re: Wildcard Virtual Host in Apache2

Post by panic! »

pasting error TEEEHEEEEEEE.
Post Reply