Wild Card Subdomains
Posted by: cayofuego (---.dsl.bell.ca)
Date: March 01, 2010 05:00PM

In my hosts file I created the following entry
127.0.0.1 my-site.com

I'm trying to setup dynamic subdomains.
Eg.
subdomain1.my-site.com
subdomain2.my-site.com
subdomain3.my-site.com

Basically I should be able to type in any subdomain and it should automatically point to a matching folder

Eg.
subdomain1.my-site.com will point to "C:\wamp\www\subdomain1"
subdomain2.my-site.com will point to "C:\wamp\www\subdomain2"
subdomain3.my-site.com will point to "C:\wamp\www\subdomain3"

I read about VirtualHosts but from I gather I would have to create an entry for each subdomain ( which is not what I want ). Is there a way to create only 1 entry that will handle any subdomain I type in and automatically point to a matching subfolder?

Thanks,

Re: Wild Card Subdomains
Posted by: c2dan (---.15-1.cable.virginmedia.com)
Date: March 01, 2010 07:59PM

You can use mass virtual hosting with Apache as explained here
http://httpd.apache.org/docs/2.2/vhosts/mass.html

You'll still need to add each subdomain to the hosts file. Windows does not support wildcards for host definitions.

Re: Wild Card Subdomains
Posted by: cayofuego (---.dsl.bell.ca)
Date: March 01, 2010 09:26PM

I can't seem to figure this out. If I can get this working in wamp it would really make development so much easier.

Do I need to alter "httpd-vhosts.conf" located in "conf/extra/httpd-vhosts.conf"

I added this in and restarted services but Apache never comes back up.

<VirtualHost 127.0.0.1>
VirtualDocumentRootIP "C:/wamp/www/%1"
</VirtualHost>

Any help would be greatly appreciated.

Thanks,

Re: Wild Card Subdomains
Posted by: c2dan (---.15-1.cable.virginmedia.com)
Date: March 01, 2010 10:56PM

First you need to enable the mod_vhost_alias module

Left click wamp tray icon choose Apache > Module > vhost_alias_module

You need to something like the following in "conf/extra/httpd-vhosts.conf" as per example in the documentation linked above.
# get the server name from the Host: header
UseCanonicalName Off

# this log format can be split per-virtual-host based on the first field
LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon
CustomLog logs/access_log vcommon

# include the server name in the filenames used to satisfy requests
VirtualDocumentRoot /www/hosts/%0/docs
VirtualScriptAlias /www/hosts/%0/cgi-bin

You do not use <VirtualHost></VirutalHost> tags. Just the directives posted above. I can only suggest you to go through the documentation linked above to understand how to use mass virtual hosting.

Re: Wild Card Subdomains
Posted by: yfastud (Moderator)
Date: March 02, 2010 01:16AM

the question is "do your dns/registra allow you to use wildcard?" if not, it will never work out for you since when you type a wildcard sub in browser, it will go to your dns, and if supported, your dns will reroute browser request to your wamp pc

Have fun,

FREE One A Day
FREE Photo
FREE Games
FREE Websites
FREE Portable GPS
FREE WAMP Guides

Sorry, only registered users may post in this forum.