所以我使用的是 Codeigniter 2.1 Internationalization i18n Library我需要调整我的路线以在我删除 Controller 名称的短网址中使用语言参数:
$route['default_controller'] = "home";
#$route['^(en|es|ro)/(.+)$'] = "$2";
#$route['^(en|es|ro)$'] = $route['default_controller'];
$route['results$'] = "fetch/results";
$route['video/(:any)'] = "fetch/video/$1";
$route['tag/(:any)'] = "fetch/tag/$1";
$route['404_override'] = '';
所以我需要让这个工作 http://localhost/app/en/results?query=t-shirts
而不是 http://localhost/app/en/fetch/results?query=t 恤
我怎样才能做到这一点?
编辑:
$route['^(en|es|ro)/results$'] = "fetch/results";
$route['^(en|es|ro)/video/(:any)'] = "fetch/video/$1";
$route['^(en|es|ro)/video/(.+)$'] = $route['^(en|es|ro)/(.+)$'] = "$2";"fetch/video/$2";
以上均无效。
如果我这样做 http://localhost/app/en/fetch/video/asfasf
完美运行
这不是http://localhost/app/en/video/asfasf
我收到的错误是 404:
404 Page Not Found
The page you requested was not found.
发现问题
所以,出于某种原因,设置了这个:$route['^(en|es|ro)/(.+)$'] = "$2";
在我尝试之前是造成问题的原因。
最佳答案
这违背了 Controller 的目的,但如果您知道任何以“结果”作为第二段的内容都应该使用“获取” Controller ,您可以这样做:
$route['^(en|es|ro)/results$'] = "fetch/results";
编辑:
这是因为您的 (:any)
行在正确的行之前出现。也 ”。” (点)字符也会匹配正斜杠,这可能不是您想要的。
$route['^(en|es|ro)/results$'] = "fetch/results";
$route['^(en|es|ro)/video/([^/]+)$'] = "fetch/video/$2";
$route['^(en|es|ro)/video/(:any)'] = "fetch/video/$1";
关于php - 为语言路径设置 codeigniter 路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8719407/