1

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
Geo
  • 3,160
  • 6
  • 41
  • 82
  • This may help. http://serverfault.com/questions/63200/how-do-i-create-subdomain-names-dynamically The logic is there but it'll be hard if you aren't running Apache. – TRose Jul 16 '15 at 14:43
  • Is your site in an IIS server? – rrk Jul 17 '15 at 08:07
  • @RejithRKrishnan yes it is. I will try your solution below and let you know. Thanks! – Geo Jul 20 '15 at 13:30

1 Answers1

1

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.

rrk
  • 15,677
  • 4
  • 29
  • 45
  • So this is creating bindings for each of my users if I understand it correctly? What is the difference if I just add the usernames manually as bindings on IIS? – Geo Jul 22 '15 at 09:12
  • @Geo I am not sure. I don't think there is anything to do with users in the case of IIS website bindings. Only thing necessary is that coldfusion have administrative privileges for the command to be executed. – rrk Jul 22 '15 at 10:02