I am using the multilingual feature in my Codeigniter website. current URL looks like
http://example.com/hi/news/view/news-title
I want this like
http://example.com/hi/news/news-title
current routes.php is looking like
$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 file looks like
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]
I tried these but it not works and always give me 404 error
$route['^(en|hi)/news/(:any)'] = "news/view/$1";
$route['hi/news/(:any)'] = 'news/view/$1';
You have not specified the name of the controller or the controller called "News" is not exists.
Specify the name of the controller that is having the "news" method eg
$route['(en|hi)/news/(:any)'] = "home/news/view/$1";
OR
Create a "News" controller and create a "view" method eg
class News extends CI_Controller {
public function view()
{
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.