Question

I've configured Codeigniter 2.1 with i18n and extended controller.

I've hide the main controller "main" and I kept visible "admin" and "blog" controller.

This urls works fine:

www.mysite.com/ en / functionname

www.mysite.com/ en / blog /

This is my problem: www.mysite.com/ it / blog / functionname

With the main controller "blog" everything after "/" is ignored.

Is it possible to do this?

My routes.php file:

$default_controller = "main";
$language_alias = array('it','en');
// exceptions
$controller_exceptions = array('admin','blog');
// route
$route['default_controller'] = $default_controller;
$route["^(".implode('|', $language_alias).")/(".implode('|', $controller_exceptions).")(.*)"] = '$2';
$route["^(".implode('|', $language_alias).")?/(.*)"] = $default_controller.'/$2';
$route["^((?!\b".implode('\b|\b', $controller_exceptions)."\b).*)$"] = $default_controller.'/$1';

foreach($language_alias as $language) {
    $route[$language] = $default_controller.'/index';
}

$route['404_override'] = '';

// URI like '/en/about' -> use controller 'about'
$route['^(it|en)/(.+)$'] = "$2";

// '/it', '/en' URIs -> use default controller
$route['^(it|en)$'] = $route['default_controller'];

If I remove lang in my URL everything works fine:

www.mysite.com/ blog / functionname

Was it helpful?

Solution

I think you need another segment in your routes for accessing the controllers function.

so you'll need a second line:

// '/it', '/en' URIs -> use default controller
$route['^(it|en)$'] = $route['default_controller'];
// URI like '/en/about' -> use controller 'about'
$route['^(it|en)/(.+)$'] = "$2";
// URI like '/en/about/test' -> use controller 'about' with function 'test'
$route['^(it|en)/(.+)/(.+)$'] = "$2/$3";

I don't use the i18n or support multiple language in any project atm so I can't test but this should do the trick.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top