我在Codeigniter网站上使用多语言功能。当前URL看起来像
http://example.com/hi/news/view/news-title
我想要这个像
http://example.com/hi/news/news-title
currentroutes.php看起来像
$route['default_controller'] = 'home';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
//Routes for multilingual url
$route['^hi/(.+)$'] = "$1";
$route['^en/(.+)$'] = "$1";
// '/en' -> use default controller
$route['^hi$'] = $route['default_controller'];
$route['^en$'] = $route['default_controller'];
.htaccess文件看起来像
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index.php|(.*).swf|forums|images|css|downloads|jquery|js|robots.txt|favicon.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?$1 [L,QSA]
我试过这些,但它不起作用,总是给我404错误
$route['^(en|hi)/news/(:any)'] = "news/view/$1";
$route['hi/news/(:any)'] = 'news/view/$1';
您没有指定控制器的名称,或者名为"News"的控制器不存在。
指定具有"新闻"方法的控制器的名称,例如
$route['(en|hi)/news/(:any)'] = "home/news/view/$1";
或
创建"新闻"控制器并创建"视图"方法,例如
class News extends CI_Controller {
public function view()
{
}
}