Welcome Guest, Not a member yet? Register   Sign In
How to manage subdomains?
#1

[eluser]koichirose[/eluser]
In my website I give the opportunity to change language and city (we list stores in a given city).
This is done by setting a cookie after receiving POST data.

I now would like to have urls like newyork.website.com or atlanta.website.com etc.

I managed to do this by linking to my controller (/city/city_id) which sets the cookie and then redirects to the home, but obviously the url in the browser bar changes to www.website.com again. I'd like for it to remain what the user entered (newyork.website.com)

How can I achieve this?

Thank you very much
#2

[eluser]mddd[/eluser]
I would set up the subdomains as aliases to the main domain. That means that atlanta.website.com will call exactly the same script as newyork.website.com. No rewriting whatsoever.

In CI, check out the requested host through the $_SERVER parameters. This way you won't even have to save the site in a cookie; checking the subdomain will let your code know what location to use.
#3

[eluser]koichirose[/eluser]
This is good, I guess I would have to call the script that checks $_SERVER on every page (or a use a hook for that).
Right?
But what would happen to the old www.website.com ? I'd have to shut it down, because you have to define a city to browse the website...?
#4

[eluser]mddd[/eluser]
Exactly. An autoloading model or a hook would be perfect for it.

With regards to the "no location" users I see three options:
1) select a default location. eg. if no location is given, you move them to newyork.site.com automatically. works if you have one "main" location.
2) if no location was selected, show them a "choose your location" page. save the choice in a cookie. if they come in without a location the next time, you can redirect them to their previously selected location
3) make a 'overall' version of the site. Eg. if you are a news site, www.site.com can show news from all over the place, in stead of only from the selected location. Clicking on a news article could then send the user on to the site/location that article came from.
#5

[eluser]koichirose[/eluser]
Thank you very much, I think I'll go with option 1 or 2 Smile
Very helpful




Theme © iAndrew 2016 - Forum software by © MyBB