简体   繁体   中英

URI multilingual CodeIgniter

We're using Codeingiter library i18n ( link ) to create a multilingual site.

Before this, we had for example www.thedomain.com/register and register was a function in our controller. Now when we put this library it grabs the domain, the language string, the controller's name and the functions name: www.thedomain.com/es/homegf/register (where homegf is our controller).

We want this URI's to work without the name of our controller on it (www.thdomain.com/es/register) like in the librarie's examples but we think the problem is in our routes.php.

This is what we have in routes.php

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$route['default_controller'] = "homegf";
$route['404_override'] = '';
$route['^(en|es|de)/(.+)$'] = "$2";
$route['^(en|es|de)$'] = $route['default_controller'];

This is our .htaccess

RewriteEngine on
RewriteCond $1 !^(index\.php|files|robots\.txt)
RewriteRule ^(.*)$  /index.php/$1 [L]

You can find our code to review it at https://bitbucket.org/ticketcomunicacion/grinfood/src/17ddde60e340a1f2bc389f54ec579e1e903ee86b?at=multilenguaje

as i understand , you want the controller url without controller name .

if you want to change the URL from your controller name to other ,

in your routes.php write the following

$route['homegf/register'] = "register";

and you can access

domain.com/es/register

The problem was in our routes.

This is how we managed to make it work:

$route['^es/(.+)$'] = "homegf/$1";
$route['^en/(.+)$'] = "homegf/$1";

$route['^es$'] = $route['default_controller'];
$route['^en$'] = $route['default_controller'];

$route['(:any)'] = 'homegf/$1';

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM