CodeIgniter Forums
Problem with route and URI Language code - 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: Problem with route and URI Language code (/showthread.php?tid=7734)



Problem with route and URI Language code - El Forum - 04-21-2008

[eluser]deck1[/eluser]
Hi,

I'm having problems with the following route:

Code:
$route["([a-z]{2}(?:-[A-Z]{2})?/?)?(.*)"] ='$2';

I want urls with language code in the first segment, but that code may be "en" or "en-US" or nothing.

It works ok for the following URLs:
http://www.domain.com/
http://www.domain.com/en
http://www.domain.com/en/
http://www.domain.com/en/controller/...
http://www.domain.com/en-US
http://www.domain.com/en-US/
http://www.domain.com/en-US/controller/...


But fails (returns 404 page) with:
http://www.domain.com/controller/...


I have tried almost everything but i don't get it to work.

any suggestions?

Thanks in advance.


Problem with route and URI Language code - El Forum - 04-21-2008

[eluser]KeyStroke[/eluser]
Here's how I did it in my application:
Code:
$route['(en|ar|de|nl|es|fr|ru|pt)*/*(.*)'] = '$2';
I have valid language codes in my regex as you can see. This will route (for example) this:
http://example.com/ar/controller

to this:
http://example.com/controller

And you can still access the controller directly without problems.

Hope this helps.


Problem with route and URI Language code - El Forum - 04-21-2008

[eluser]deck1[/eluser]
Thanks KeyStroke.

But i have some restrictions. I don't know the language code at this point (i will check later against DB), therefore i have to allow that pattern: "xx" or "xx-XX". And (and here comes the problem) both patterns are allowed, and both are optional.

If i try a single pattern, as yours, it works ok, but i have to allow both.