Forum Moderators: phranque

Message Too Old, No Replies

Subdomains in a folder

How can I create a vhost so subdomains exist in a folder.

         

jnuneznyc

7:48 pm on Aug 10, 2004 (gmt 0)



How can I create a vhost entry so that every folder added to the DOCUMENT_ROOT can be a subdomain. For example, I have a folder called "subs" this folder sits outside of htdocs for "mydomain.com". How can I set up vhost entry so "games.mydomain.com" will goto "subs/games" and "www.mydomain.com" / "mydomain.com" will continue to go to the main site. I need this to be dynamic so the folder can be removed to disable the subdomain (or redirect to the main site)

Thanks,
JNunezNYC

encyclo

7:56 pm on Aug 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your best bet is to start here:

Dynamically configured mass virtual hosting [httpd.apache.org]

jnuneznyc

8:46 pm on Aug 10, 2004 (gmt 0)



Thanks. The system I have in place is currently using a separate virtual host configuration file for each subdomain. The vhost file is created by a PHP script. My problem is that once I add/delete a subdomain I need to restart apache (manually). The additions rarely happen but I figure that there must be a better way to perform this task.

I think it's possible with mod_rewrite but the docs are over my head. I remember one of my old ISP's having the user home pages as username.isp.com

Thanks Again,

jdMorgan

9:07 pm on Aug 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



JNunez,

Welcome to WebmasterWorld!

The code posted in this thread [webmasterworld.com], while intended for use in .htaccess, can be easily modified to help with a piece of your problem -- that of mapping arbitrary subdomains to subfolders, without having to define each new subdomain as it is added.

In conjunction with wildcard DNS and a simple RewriteRule to treat "mydomain.com" and "www.mydomain.com" as exceptions that should not be mapped to /subs, this technique will allow you to do what you want.

It's a fairly complex piece of code, considering its small size, so please review the documents cited in our Apache Forum Charter [webmasterworld.com] so you'll be able to use it with confidence.

Jim