Geo
Geo

Reputation: 3200

Dynamic Subdomains - ColdFusion 11

Anyone know a way to create dynamic subdomains in coldfusion 11 without having to add them to a dns server?

I want to be able to redirect each of my clients in a personalized subdomain every time they log in to my system.

ex: client1.example.com client2.example.com

Upvotes: 1

Views: 183

Answers (1)

rrk
rrk

Reputation: 15866

This works if your site is hosted in a Windows IIS server.

If you are using IIS then the following can help you. Use loops and conditions as your requirements.

<!--- Provide you IIS SiteName --->
<cfset siteName = "Your IIS Site Name">
<!--- Your new domain address --->
<cfset newSiteBinding = "client2.example.com">
<!--- your port address --->
<cfset newSitePort = 80>
<cfset fileID = createUUID()>
<cfsavecontent variable="ex"><cfoutput>cd %windir%\system32\inetsrv
%windir%\system32\inetsrv\APPCMD set site /site.name: #siteName# /+bindings.[protocol='http',bindingInformation='*:#newSitePort#:#newSiteBinding#']</cfoutput>
</cfsavecontent>
<cffile  action = "write"
    file = "E:\#fileID#.bat"
    output = "#ex#"
/>

<cfexecute  name="E:\#fileID#.bat"
    arguments="/c set"
    variable="data"
    timeout="10" 
/>

<cffile  action = "delete"
    file = "E:\#fileID#.bat"
>

What we are basically doing is that we are creating a .bat file and executing it using cfexecute. Please note that you need to be careful with the paths because the Directory structure might be different in your server.

.BAT file content Example

cd %windir%\system32\inetsrv
%windir%\system32\inetsrv\APPCMD set site /site.name: example /+bindings.[protocol='http',bindingInformation='client2.example.com:80:*']

How the command works. Notice the + at /+bindings?

That means adding a new binding and /-bindings tries to remove an existing binding.

Upvotes: 1

Related Questions