Welcome Guest, Not a member yet? Register   Sign In
Subdomains
#1

[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.
#2

[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.
#3

[eluser]CodeIgniterNewbie[/eluser]
Checking the subdomain is not the problem. The problem is routing the user to the correct controller. Suggestions?
#4

[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?
#5

[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.
#6

[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.
#7

[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.
#8

[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.
#9

[eluser]CodeIgniterNewbie[/eluser]
Are you talking about config['base_url'] in /config/config.php?
#10

[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?




Theme © iAndrew 2016 - Forum software by © MyBB