I'm a fairly avid programmer, but recently moved to web development, so I apologize if this question is somewhat silly.

I'm building an e-commerce webApp that should support multiple domains. Lets say I have 2 stores running in my App, each one having its own custom domain.

The app is located at: www.main-app.com
The store 1 is located at: www.store1.com
the store 2 is located at: www.store2.com

I need to redirect all requests made in store1.com and store2.com to the main-app.com passing an id, which is the store Id. the store Id is used to load all components of each store.

I've managed to add CNAME records to store1 and store2 pointing to www.main-app.com. So far so good, when I type www.store1.com in my browser, the main-app shows on screen, but how can I pass the store Id so it knows which store to load?

Which would be the best approach to make this feature possible?

In essence, I want to type www.store1.com and www.main-app.com receives a request to load store1. I don't want to use domain forwarding, like typing www.store1.com and it redirects the user to something like www.main-app.com?storeId=1.

I hope I made myself clear.


The web browser will send a Host header along with each request to your web application. This header will contain the domain used to access the site. You can use this header to change the look and feel of the site based on the domain the user is using the access it.


Any number of records can point to the same server which will make the server get requests from all domains. Usually this is used to host multiple domains using one web server. The servers knows which the request is for since HTTP 1.1 which added a field in the header for the requested hostname.

On Apache, when you host multiple domains, you create a VirtualHost and normally give them each a path to the location of their files. For what you describe though, you would create a virtual host for each store but set all their root folders to the same path which would have the files for your main app.

In the application itself you would not even need an ID because all requests will some in with a field which tells you which host the request if for. With that you can index any data which is different between stores. There is no need to redirect anything in this case.

Apache can automate the process using a RewriteRule which requires mod_rewrite installed and enabled. What you do it tell it to invoke pages with a different parameter depending on the requested domain. For example, you could tell it to add a storeId to every request as you suggested and use that storeId to drive the logic. Other web servers probably have something equivalent, I'm just using Apache to describe this as it is the one I know best.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.