Reputation: 417
I have a Project in Codeigniter that will be in two languages, however I need to allow this language change only in the project URL;
That is, when accessing the domain.com.br it should maintain as a base url / pt on all pages and consecutively the same thing with / en;
Has anyone ever had to do this inclusion? Here is the code for my .htaccess, config and constants:
Htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteCond %{HTTP_HOST} ^www\.(.*)
#RewriteRule (.*) http://%1/$1 [R=301,L]
RewriteBase /cliente/em_desenvolvimento/back/mauricio/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</ifModule>
Config:
$config['base_url'] = 'http://192.168.110.4/cliente/em_desenvolvimento/back/mauricio/';
Constants:
define('PATH_FRONT_END', $_SERVER['DOCUMENT_ROOT'] . '/cliente/em_desenvolvimento/back/mauricio/');
define('PATH_FRONT_END_UPLOAD', $_SERVER['DOCUMENT_ROOT'] . 'cliente/em_desenvolvimento/back/mauricio/web_files/uploads/');
I believe that something can be accomplished on the routes, but I have no idea how this can be done.
Upvotes: 1
Views: 73
Reputation: 417
A constant was created to play the language in the url:
define('base_path', 'cliente/em_desenvolvimento/back/mauricio/');
$uri_path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$uri_path = str_replace(base_path, '', $uri_path);
$uri_segments = explode('/', $uri_path);
switch ($uri_segments[1]) {
case 'pt':
define('idioma_site', 'pt');
break;
case 'es':
define('idioma_site', 'es');
break;
case 'en':
define('idioma_site', 'en');
break;
case 'cms':
break;
default:
header('location: http://192.168.110.4/cliente/em_desenvolvimento/back/mauricio/pt');
//header('location: http://192.168.110.4/cliente/em_desenvolvimento/back/bernardo/pt');
exit();
break;
}
Upvotes: 1