Problem with route and URI Language code |
[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.
[eluser]KeyStroke[/eluser]
Here's how I did it in my application: Code: $route['(en|ar|de|nl|es|fr|ru|pt)*/*(.*)'] = '$2'; http://example.com/ar/controller to this: http://example.com/controller And you can still access the controller directly without problems. Hope this helps.
[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. |
Welcome Guest, Not a member yet? Register Sign In |