Link to home
Start Free TrialLog in
Avatar of WestCoast_BC
WestCoast_BCFlag for Canada

asked on

Can I have multiple URLs sharing the same code and database but preserve the URL at all time that is displayed

Is there a way to have multiple subdomains and domain all point to the same IP address but use their own data?

I have a tool for creating websites that is written using Coldfusion, jQuery and uses a MySQL database. Right now each time I create a new site I need to upload a copy of the code and create a MySQL database. This is very time consuming and I am hoping for a more automated method.

Is there way using perhaps redirects so that I can have all the subdomains and domains share the same code and database? I need to preserve the URL that is displayed to the user. Is there a way to test the URL being used and then from that I could create session variable for pointing to custom directories and the site specific tables in the database.

Thank you for any help you can provide.
Avatar of ste5an
ste5an
Flag of Germany image

Yes, we do this all the time.    Each subdomain is for a different client but all the code and the database is the same.

Have the subdomains all point to the same website and database, then just distinguish your user by assigning the subdomain to a particular client.   Get the subdomain from the URL..

<cfset thisClientDomain = listFirst(cgi.server_name,".")>

Then find out which client uses this subdomain by associating it with a customer in the database...

  select customerID from customers where subdomain = '#thisClientDomain#'

Then assign it to a session variable...

<cfset session.customerID = myQuery.customerID>

Throughout the code, just fetch the records of this client...

  select * from orders where customerID = #session.customerID#

  select * from users where customerID = #session.customerID#
Avatar of WestCoast_BC

ASKER

Thank you gdemaria  - do you do this in OnSessionStart in Application.cfc?
ASKER CERTIFIED SOLUTION
Avatar of gdemaria
gdemaria
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial