我有一个基于codeigniter v3的应用程序,有5种语言(ar,en,ru,es,fr),阿拉伯语是默认的,这是(添加资金)页面链接:
app.com/add_funds
app.com/en/add_funds
app.com/ru/add_funds
app.com/es/add_funds
app.com/fr/add_funds
一切工作如预期,但当我设置了一些路由404的别名!
$route['deposit'] = 'add_funds/index';
app.com/add_funds // ok
app.com/en/add_funds // ok
app.com/ru/add_funds // ok
app.com/es/add_funds // ok
app.com/fr/add_funds // ok
app.com/deposit // ok
app.com/en/deposit // 404
app.com/ru/deposit // 404
app.com/es/deposit // 404
app.com/fr/deposit // 404
我的代码:
routes.php:
$route['default_controller'] = 'home';
$route['(\w{2})/(.*)'] = '$2';
$route['(\w{2})'] = $route['default_controller'];
$route['404_override'] = 'custom_page/page_404';
$route['translate_uri_dashes'] = false;
$route['deposit'] = 'add_funds/index';
.htaccess权限:
RewriteEngine On
Options +FollowSymLinks
Options -Indexes
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule . index.php [L,QSA]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
基本控制器功能:
function init_app_lang(){
global $URI;
$CI = &get_instance();
$supported_langs = ['en'=>'english','ru'=>'russian','es'=>'spanish','fr'=>'french'];
$uri_abbr = $URI->segment(1);
if ( isset($supported_langs[$uri_abbr]) && strlen($uri_abbr) == 2 ) {
$langDefault = $supported_langs[$uri_abbr];
set_session('langCurrent', $langDefault);
}else{
$langDefault = "arabic";
set_session('langCurrent', $langDefault);
}
}
谢谢&对不起我的英语
1条答案
按热度按时间0qx6xfy61#
通过从路由数组中通过$值替换$瓦尔($alias key)变量,修复了此问题
Router.php