0

In CI, I have made 2 projects for same site in 2 language. Now based on some condition say continent from where the site is opened I want to change the view of the site. E.g. If I open the site from Asia, english language site will open and if I open the same site from South America, spanish language site will open. I am successful in finding from where the site is being opened from but I am not able to point to different folders based on the continent. How am I to achieve this? I have placed english folder and spanish folder in public_html.

Any help/suggestions will be welcome.

samjhana joshi
  • 1,995
  • 4
  • 35
  • 69

3 Answers3

1

You can use PHP switch

switch ($continent){
  case ('asia'):

    redirect ('location of one content');
    break;
case ('south_amrica'):

    redirect ('location of one content')
    break;

}

make sure you define the routes too. Hope this help.

mdamia
  • 4,447
  • 1
  • 24
  • 23
1

I think this approach works fine for you:

Make for each language a subdomain. Point each subdomain to the specific language folder. You know the wished language, so redirect to the subdomain.

  • en.foo.com -> public_html/english
  • es.foo.com -> public_html/spanish

Subdomains are great for SEO goals. You can optimize the subdomains for the specific language.

Most used control panels support this feature: DirectAdmin, cPanel, etc. If not supported, you can do that with .htaccess: .htaccess rewrite subdomain to directory

Alternative is making a route, such as foo.com/en, but that's possibly difficult with route conflicts.

Important

Exclude search robots from your geobased language choice! Let the robots index both sites.

Community
  • 1
  • 1
schellingerht
  • 5,726
  • 2
  • 28
  • 56
0

if you hava two different CI Codes then you can change aaplication folder names and combine system file.

then in index.php you can set your application folder based on your conditions.

BUT if you have to change only view pages then write your condition in Loader.php file in system/core/Loader.php to rewrite view path.

public function __construct()
    {
        $this->_ci_ob_level  = ob_get_level();
    $this->_ci_library_paths = array(APPPATH, BASEPATH);
    $this->_ci_helper_paths = array(APPPATH, BASEPATH);
    $this->_ci_model_paths = array(APPPATH);
    $this->_ci_view_paths = array(APPPATH.'views/'  => TRUE);  /* Change view path based on your requirement */

    log_message('debug', "Loader Class Initialized");
}

By following these steps you do not have to change your code..

Vishal Rambhiya
  • 741
  • 6
  • 10