Welcome Guest, Not a member yet? Register   Sign In
Problem with route and URI Language code
#1

[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.
#2

[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.
#3

[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.




Theme © iAndrew 2016 - Forum software by © MyBB