I'm trying to create a site with CodeIgniter. I will have multiple domains served from this server, and what I am trying to do is to separate the HTTP requests for www.example1.com from the ones for www.example2.com and then redirect them to the their correct application folders.
Say this is my directory structure:
- system
- application
- example1
- example2
- application
So this request
www.example1.com/gallery/
would then be redirected to exmaple1 folder.
Does anyone have any code example for doing this? Obviously you would need to use the ReWrite module...
I looked around the Apache documentation but I couldn't get anywhere. Let me know if you need more information on this.
What you need is called VirtualHost to make www.example1.com and www.exaplme2.com point each to a different folder in your filesystem.
If you additionally wish to have a different path in the URI for serving the main content you have various alternatives:
Physically create the folder and do no further changes
Physically create a link (named gallery pointing to the main virtualhost root folder) to the folder and use the FollowSymLinks option for the VirtualHost
Use an Alias directive in the VirtualHost
Use mod_rewrite
The simplest (CodeIgniter permitting) would be the option 1 or 2.
Snippet from the VirtualHost documentation:
Using VirtualHost (and Alias, Rewrite) are the primary answers, but if you think you will be adding/removing other hosts using the same setup, then I would consider the mod_macro module. This is a third party module that will help you to simplify apache configuration and avoid copy/paste errors.
A simple example with your layout, define the following:
And then when enabling a site, use the following directive:
Which will setup www.example1.com to use the configured directory as root as well as the configured logging directory.
This is really two questions:
how to make www.example1.com and www.example2.com different? The answer to this is the VirtualHost directive.
How to make /gallery point to example1? This is done with the Alias directive.