Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic Sub-Domains 1

Status
Not open for further replies.

tleish

Programmer
Jan 17, 2001
619
US
I'm creating a comunity on a IIS server with ColdFusion where a user can create their own site using my applications. I want to be able to dynamically create sub-domains depending when the user registers, (ex. username.domainname.com), but I'm not quite sure how to do this dynamically or if it's even possible.

One person suggested creating the wildcard sub-domains (*.domainname.com) and depending on what was in the actual url a different site would show up via a CF script(ex. joe.domainname.com would acces the site in the "joe" folder). Does anyone know if this is even possible or if there's another easy way to set up sub-domains?

-tleish
 
Hi tleish,

Yes this is possible. I administer several dns servers and I've never used a wildcard subdomain but I did just verify that they work. You'll just need to have your dns administrator add this line to your domain name's zone file.

* IN A 10.10.10.1 ( <- substitue your IP)

This will then allow anything.yourDomainName.com to point to your site. Then, just configure your default page like this.

<cflocation url=&quot;/#listgetat(cgi.server_name,&quot;1&quot;,&quot;.&quot;)#/index.cfm&quot;>

The &quot;#listgetat(cgi.server_name,&quot;1&quot;,&quot;.&quot;)#&quot; is the first part of the virtual domain name ( ex. jsmith for jsmith.mydomain.com). The cflocation will then re-direct to a sub-folder as in &quot; If you don't want the sub-directory to be part of their home page url, let me know as the solution becomes more complex.

Hope this helps,
GJ
 
Thank you for looking into that for me.

Is there a way to not have the directory as part of their home page?

What if you main index page at (and every subsequent page) checked to see if there was a subdomain, and if so replace that page (index.cfm) with different content using CFINCLUDE?
 
If you only allow certain page names, then yes. Instead of a <cflocation>, you could use a <cfinclude template=&quot;#listgetat(cgi.server_name,&quot;1&quot;,&quot;.&quot;)#\index.cfm&quot;> as you mentioned. The problem is that if they link to another file, it will need to be in your root directory. If they create a login page located at &quot;jsmith.mydomain.com/login.cfm&quot;, you will have to have a file called &quot;login.cfm&quot; in your root directory to avoid a 404 error. If you allowed only certain page names such as index.cfm, login.cfm, info.cfm, etc..., you could then setup these files in your root directory and use the <cfinclude> approach to load the appropriate file from the user's directory. I don't think this is a realistic approach but it's the only real way I see to do that. I suppose you could set it up this way and everytime they upload a page, it checks to see if there is a page by that name in the root and then creates one with the cfinclude in it. Over time, most of the common page names would be in the root directory and they would simply include the appropriate file from the users directory. Another alternative would be to require that users link to any secondary pages in their subdirectory so all links from the home page would have to be domain.com/jsmith/page2.cfm&quot;.

Hope this helps,
GJ
 
I was just looking at and realized that I think this is exactly what they do. They have all sorts of subdomains, and their adding new ones all the time.

They have the directory , but it redirects you to .

I bet they use the wildcard and the exact same thing that GunJack meantioned in his first reply.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top