Wildcard subdomains for one encoding application

Basically I am trying to make a codeigniter application with localization subdomains in such a way that if I get access:

ca.site.com โ†’ it will run the same system, but will display Canadian content. us.site.com โ†’ still works with the same system, but shows American content.

plus, if I access www.site.com, it will automatically get the correct localization using ip2country and will be redirected as if from uk, redir to uk.site.com

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

root / system / expression index.php

now i want the urls to stay depending on what kind of localization they are. as:

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

how can i implement this?

Sorry if my request is a little rude. but I hope someone can help me.

+6
source share
2 answers

There are probably many ways to do this ... but the one I can think of from my head is to put something in the index.php file where the pre-configured values โ€‹โ€‹of custom configurations are set that do 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 the config.php file

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

... or you can simply override base_url in the index.php file in the $ assign_to_config array based on the value of $ _SERVER ['HTTP_HOST']. Then in any other controllers or something else that you can rely on

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

And then just list all the subdomains in the same directory and localize in your application.

+2
source

You will need to find a way to enable dynamic subdomains redirects (apparently, this is possible with a little magic .htaccess mod_rewrite), and then create a master controller with the first parameter by the index method, which is the language, then redirect the subdomain from (.*).site.com/(.*) = site.com/$1/$2 , this should work, but it does not follow the traditional MVC CodeIgniter approach and is more of a hack than the right way to do it, I'm sure someone else will learn more semantic way to work with it.

If I remember correctly, subdomain redirection is documented somewhere on apache.org and you will find more information than I pointed to google

0
source

Source: https://habr.com/ru/post/887432/


All Articles