![]() |
Routing in Multilanguage (first segment is ignored) - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=31) +--- Thread: Routing in Multilanguage (first segment is ignored) (/showthread.php?tid=77147) |
Routing in Multilanguage (first segment is ignored) - yamahdico - 07-25-2020 How can the first segment of URL, which specifies the language, be ignored in Routes.php? --- A suggested way that does not work: $routes->add('{locale}/(:any)', '\App\Controllers\$1::index'); --- A suggested way that does not work: $routes->get('{locale}/(:any)', '$1::index'); --- A suggested way that does not work: $routes->setAutoRoute(true, 1); // second parameter as the offset, first segment is ignored. --- A suggested way that does not work: $routes->add( '(:segment)/(:segment)/(:segment)/(:any)', '\$2::$3/$4' ); $routes->add( '(:segment)/(:segment)/(:segment)', '\$2::$3' ); $routes->add( '(:segment)/(:segment)', '\$2::index' ); $routes->add( '(:segment)', '\Default::index' ); $routes->add( '(:segment)/(:segment)/(:segment)/(:any)', '\\$2::$3/$4' ); $routes->add( '(:segment)/(:segment)/(:segment)', '\\$2::$3' ); $routes->add( '(:segment)/(:segment)', '\\$2::index' ); $routes->add( '(:segment)', '\\Default::index' ); --- A suggested way that does not work: $route['^(\w{2})/(.*)'] = function($language, $link) use ($route) { return isset($route[$link]) ? $route[$link] : $link; }; $route['^(\w{2})$'] = $route['default_controller']; RE: Routing in Multilanguage (first segment is ignored) - yamahdico - 07-25-2020 Why can't I use the dollar sign($1) instead of the control name? RE: Routing in Multilanguage (first segment is ignored) - jreklund - 07-25-2020 Please see here for in depth description on why $1 or any other number dosen't work for the first replacement. It thinks $ are a literal string, and not a replacement character. https://forum.codeigniter.com/thread-77045-post-378068.html#pid378068 |