CodeIgniter Forums
CI RegEx route issue - 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: CI RegEx route issue (/showthread.php?tid=7389)



CI RegEx route issue - El Forum - 04-07-2008

[eluser]KeyStroke[/eluser]
I'm trying to make a site where the content's language is specified in the first URI segment. For example:

example.com/en/product/1 (English)
example.com/ar/product/1 (Arabic)

and so on.

How do I set routing so that it always treats the second segment (which is "product" in this case) as the controller, and not the first one?

I tried this:
Code:
$route['ar/(*)'] = "$1";
$route['en/(*)'] = "$1";

But it didn't work.

Will someone help me with this please?


CI RegEx route issue - El Forum - 04-07-2008

[eluser]champs[/eluser]
Your basic flaw is not having a period in your captured pattern, i.e. "(.*)". Without knowing your specific needs, this is a low-complication example of what you'd do if you want to be specific about which languages are allowed:

Code:
$route['(en|ar|de|nl|es|fr|ru|pt)*/*(.*)'] = '$2';



CI RegEx route issue - El Forum - 04-07-2008

[eluser]KeyStroke[/eluser]
That works wonderful. Thanks champs !! I apparently suck at RegEx. Smile