Redirect URL multilanguage Codeigniter - php

I'm adding multilanguage options for a website in CodeIgniter.
I'm using this library
https://github.com/bcit-ci/CodeIgniter/wiki/CodeIgniter-2.1-internationalization-i18n
The only problem i'm having is if y access www.domain.com
The redirect goes to www.domain.com/es/welcome/index
$route['default_controller'] = "welcome/index";
$route['^(es|en)'] = "welcome/index";
$route['^(es|en)/(.+)$'] = "welcome/$2";
I don't know how to only redirect to www.domain.com/es or www.domain.com/en
when entering www.domain.com
Is that possible with this library?

//$this->default_uri = $RTR->default_controller;
$this->default_uri = '';
change line in MY_Lang.php

Related

add site/index.php/city as a codeigniter url routing not working

I have writing codeigniter URL routes for my site, the route is
$route['index.php/([a-zA-Z0-9---_%])+'] = 'site/index/$1';
when i try to access the link like as below
http://localhost/site/index.php/india
is not working, it redirects to 404 page.
If you have a link
http://localhost/site/index.php/india
You need write this route:
$route['site/index.php/(:any)'] = 'site/index/$1';

CODEIGNITER Custom redirect with only domain name in url

In codeigniter I set in routes.php the default controller:
$route['default_controller'] = 'home';
and the roules to use the lang in url
$route['^(en|es|it)/(.+)$'] = "$2";
$route['^(en|es|it)$'] = $route['default_controller'];
when I write the url in the browser domain.com there is a redirect to domain.com/it/home/index
I would like that the url will be domain.com/it without /home/index
Somebody can help me?

Change the extension of a URI in CodeIgniter

I am making an API in PHP.
I want to add .json to the URL like this:
www.example.com/data.json
I am using CodeIgniter.
I have tried solving this in routes config file like this
$route['default_controller'] = 'data';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['/data.json'] = "/data/index";
You can add a url suffix in CodeIgniter by going to the config.php file and changing url_suffix:
$config['url_suffix'] = '.json';
This will make your website accesible via www.example.com/data and www.example.com/data.json
Check the documentation
If you want to enable it in some pages only you can use the routes like this:
$route['data.json'] = 'data/index';
If it's a page with dynamic path for example data/some-id.json use this:
$route['data/(:any).json'] = 'data/index/$1';

Duplicate content on multi language URL structure

I am using CodeIgnitore to develop a multi language website. At the moment I have set up the routing as follows.
$route['default_controller'] = "home";
$route['^(en|fr)/(.+)$'] = "$2";
$route['^(en|fr)$'] = $route['default_controller'];
$route['404_override'] = '';
Now I have the ability to access the homepage with the following URLs
domain.com
domain.com/en
Both these URLs shows the home page in english so will this be penalized for duplicate content & affect SEO. I have other URLs that would cause the same issue. Is there any solution this?
Thanks.
you can redirect domain.com -> domain.com/en.
So you don't have duplicate content.
In your home.php (application/controllers/home.php):
function __construct(){
parent::__construct();
if(!preg_match("/(en|fr)/",$_SERVER['HTTP_HOST'])){
$this->load->helper('url');
redirect('/en', 'location', 301);
}
}

CodeIgniter routing when routing url starts with variable

I am getting problem on codeigniter routing when routing url starts with variable like following -
$route['(:any)/(:any)'] = "home/index/0/N/DealsAmount/ASC/$1/$2";
i can to able to configure other routing url when i am passing values through url.
Example:
Following things work perfectly
$route['About-Us/Team'] = "aboutus/team";
$route['About-us/Jobs'] = "aboutus/jobs";
$route['About-Us/FAQ'] = "aboutus/faq";
But i use this url using varible like following --
$route['About-Us/Team/(:any)'] = "aboutus/team/$1";
$route['About-Us/Team/(:any)/(:any)'] = "aboutus/team/$1/$2";
$route['About-us/Jobs/(:any)'] = "aboutus/jobs/$1";
$route['About-Us/FAQ/(:num)'] = "aboutus/faq/$1";
then it redirects to the home page that means this routing is not working here $route['(:any)/(:any)'] is working how can i able to rout these types of url can you please advise me.
You have to put the routes with :any at the bottom. If you put it at the top other routes never get caught. This should be OK:
$route['About-Us/Team/(:any)/(:any)'] = "aboutus/team/$1/$2";
$route['About-Us/Team/(:any)'] = "aboutus/team/$1";
$route['About-us/Jobs/(:any)'] = "aboutus/jobs/$1";
$route['About-Us/FAQ/(:num)'] = "aboutus/faq/$1";
$route['(:any)/(:any)'] = "home/index/0/N/DealsAmount/ASC/$1/$2";

Categories