Wildcard subdomains for a single codeigniter application Wildcard subdomains for a single codeigniter application codeigniter codeigniter

Wildcard subdomains for a single codeigniter application


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.


You'd have to find a way to allow dynamic subdomain redirects (apparently it's possible with a little .htaccess mod_rewrite magic), then make a master controller, with the first paramater on the index method being the language, then have the subdomain redirect go from (.*).site.com/(.*) = site.com/$1/$2, this should work, but it's not following the traditional MVC approach of CodeIgniter and is more of a hack than a proper way to do it, I'm sure someone else will know a more semantic way to work this.

If I recall correctly, subdomain redirects are documented somewhere on apache.org, and you'll find more info than I've provided on google