Playing parameter in url

Asked

Viewed 56 times

0

I have a Codeigniter Project that will be in two languages, however I need to allow this language change only in the project URL;

That is, when accessing domain.com.br/pt it should keep as base url /pt on all pages and consecutively the same thing with /en;

Has anyone ever needed to make this inclusion? Below is the code of 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 something can be accomplished in Routes, but I have no idea how it can be done.

  • It is not better to work with session?

  • Not because I used the language system equal to the following answer: https://answall.com/questions/155683/site-multilinguagem-codeigniter/155708#155708 and Facebook search engines do not create session or cookie and where I have the fields with name_pt, isname_ and does not take the information when sharing the post in some external link.

1 answer

0


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;
                }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.