Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wildcard subdomains for a single codeigniter application

Basically I'm trying to make a codeigniter app with localization subdomains such that if I access:

ca.site.com -> it would run the same system but shows canadian content. us.site.com -> still runs the same system but shows american content.

plus if i access www.site.com, it would automatically get the proper localization using ip2country and would get redirected like if from uk, redir to uk.site.com

there would only be 1 system folder and 1 application folder:

root /system /application index.php

now i want the urls to stay put from whichever localization they are. like:

uk.site.com/profile/1 will access a profile controller ca.site.com/profile/3 will also access the same controller uk.site.com uses

how will i be able to implement this?

pardon me if my inquiry is a bit crude. but i hope someone can help me.

like image 681
VeeBee Avatar asked May 06 '11 07:05

VeeBee


1 Answers

There are probably a lot of ways to do this... but one that I can think of off the top of my head is to put something in the index.php file where the preloaded custom config values are established that does something like this...

/*
 * -------------------------------------------------------------------
 *  CUSTOM CONFIG VALUES
 * -------------------------------------------------------------------
 *
 * The $assign_to_config array below will be passed dynamically to the
 * config class when initialized. This allows you to set custom config
 * items or override any default config values found in the config.php file.
 * This can be handy as it permits you to share one application between
 * multiple front controller files, with each file containing different
 * config values.
 *
 * Un-comment the $assign_to_config array below to use this feature
 *
 */
    $region_prefix_var = explode('.', $_SERVER['HTTP_HOST']);
    $assign_to_config['region_prefix'] = $region_prefix_var[0];

and then in your config.php file

global $region_prefix_var;
$config['base_url'] = $region_prefix_var[0].".site.com/";

...or you could just override the base_url in the index.php file in the $assign_to_config array based on the $_SERVER['HTTP_HOST'] value. Then in any other controllers or whatever you can base things off of

$this->config->item('region_prefix');

And then just point all of the subdomains at the same directory and localize within your app.

like image 112
tgriesser Avatar answered Oct 23 '22 08:10

tgriesser