CodeIgniter Forums
Regular Expression ROUTE - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Regular Expression ROUTE (/showthread.php?tid=26980)



Regular Expression ROUTE - El Forum - 01-28-2010

[eluser]yannyannyann[/eluser]
Hi,

i can't find the right solution to my problem:

I have a bilingual website.

//english:
mysite.com/controler/function/
//french:
mysite.com/fr/controler/function/

For the page controler I'd like to removed the segment "index".

Code:
// Remove index
$route['page'] = 'page';
$route['page/(.*)'] = 'page/index/$1';

// Language (fr or en)
$route['(\w{2})/(.*)'] = '$2';
$route['(\w{2})'] = $route['default_controller'];

// this works:
mysite.com/page/help
// but this provokes a 404 error:
mysite.com/fr/page/help


Any idea ?
I am pretty sure I have to add something ot this line :
Code:
$route['page/(.*)'] = 'page/index/$1';

But What ?!


Regular Expression ROUTE - El Forum - 01-28-2010

[eluser]Isern Palaus[/eluser]
[quote author="yannyannyann" date="1264716828"]
Code:
// Remove index
$route['page'] = 'page';
$route['(\w{2})/page'] = 'page';
$route['page/(.*)'] = 'page/index/$1';
$route['(\w{2})/page/(.*)'] = 'page/index/$1';

// Language (fr or en)
$route['(\w{2})/(.*)'] = '$2';
$route['(\w{2})'] = $route['default_controller'];

// this works:
mysite.com/page/help
// but this provokes a 404 error:
mysite.com/fr/page/help
[/quote]


Regular Expression ROUTE - El Forum - 01-29-2010

[eluser]yannyannyann[/eluser]
Gracies Isern !!

It works really well.
Is there a way to learn regular expression easily ?

Because I am always a bit frustrated not being able to solve these little problems.

I know that there is a lot of documentation on the web about Reg. Expressions, but maybe you know something more 'fun' to learn ?


Regular Expression ROUTE - El Forum - 01-29-2010

[eluser]Isern Palaus[/eluser]
Hello yannyannyann,

I don't know so much about regular expresions, when I need something I google it.

By the way, I know the trick for URI language entry in wiki, I'm using it Wink

Regards
Isern