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.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ste5anSenior DeveloperCommented:
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#
WestCoast_BCAuthor Commented:
Thank you gdemaria  - do you do this in OnSessionStart in Application.cfc?
You could do it onSessionStart, but if the user changes between one subdomain and another subdomain if you are using the same application.cfc for both, it will not start a new session and will not change the customer.    So, alternatively, you would do it in onRequestStart and just remember the subdomain and check to see if it changes, if it does, then fetch the customerID again

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.