Subdomains |
[eluser]CodeIgniterNewbie[/eluser]
Assume the following subdomains: http://us.domain.com http://ca.domain.com When a user connects to one of the domains, I want to extract the subdomain part (i.e. "us" or "ca"), implement some logic (basically, set a session variable), then route the user to the appropriate controller (in the above case, the home controller). If, say, the user connect to http://us.domain.com/method1/, I still need to implement the session-setting logic, and then route the user to method1 controller. How do I do this in CI? Is this a routes issue? .htaccess issue? Some combination of both? Something else? Thanks.
[eluser]JHackamack[/eluser]
There might be an .htaccess way of doing it, but I would implement a check at every controller that parses the url (split at . and /) and provides you with that information returning the correct language to use.
[eluser]CodeIgniterNewbie[/eluser]
Checking the subdomain is not the problem. The problem is routing the user to the correct controller. Suggestions?
[eluser]JHackamack[/eluser]
So you create a model that is put in each controller to: check the subdomain set the session variable redirect based on the session variable and URL is this correct?
[eluser]CodeIgniterNewbie[/eluser]
I route based on the URL. Essentially, http://us.domain.com and http://ca.domain.com have the same controller. The session variable that is set is just used for certain logic in the background.
[eluser]JHackamack[/eluser]
So if you want to take both subdomains to the same place but only set a session variable to do something different then call a model from each constructor that splits the url to get the subdomain sets the variable then when a person comes to the site they have the session variable silently set and continue on their merry way.
[eluser]CodeIgniterNewbie[/eluser]
That is already happening. My problem is that I do not know how to have http://us.domain.com and http://ca.domain.com both route to controller-x.
[eluser]JHackamack[/eluser]
have us.domain point to the same folder as ca.domain and set up your config to use the base url of "https://".$php_domain.".domain.com"; where $php_domain is the extracted subdomain.
[eluser]CodeIgniterNewbie[/eluser]
Are you talking about config['base_url'] in /config/config.php?
[eluser]JHackamack[/eluser]
Yes, That way if a person comes to the site they will still be able to keep their respective "ca" or "us" subdomains, and CI will work just fine for them. Does this make sense? |
Welcome Guest, Not a member yet? Register Sign In |