Welcome Guest, Not a member yet? Register   Sign In
How to bypass first segment in routing?
#1

[eluser]Ki[/eluser]
I am trying to set up routing that will accommodate language in uri
there are 2 possibilities:
www.site.com/en/controller/method
www.site.com/controller/method

I have defined my languages in the array just before the routing definition:
$langs = array('en'=>'english','fr'=>'french')

Then, I do this
foreach($langs as $key=>$value){
$route["^$key/(.+)"] = "$1";
}
The above works for
www.site.com/en/products/ but not for www.site.com/en/products/page/1/

The above rule of bypassing any language definition in the uri should apply thought the site, but then some controllers need to accept (:any). Like the example above, anything like /products/blah/blah/blah/ needs to be passed to the products controller index method
the same with /en/products/blah/blah/blah/ - this too needs to go to products controller index method.

Any examples on how to accomplish this? Note that /en/help/contact_us needs to go to help controller, contact_us method - not all routes use (:any)
#2

[eluser]mddd[/eluser]
The problem is not in the language but in the fact that for some controllers you want to keep all the segments and for others you want to reroute to the index method.

A simple solution would be to keep the route just as it is, and use the _remap method in all controllers that use the index method (even when arguments are present).
The route takes care of stripping off the language. The _remap method does the rest.
#3

[eluser]Chicken's Egg[/eluser]
What about putting the following line in your configuration routes.php file:
<?php
$route['([a-z]{2})/(.[^/]+/.[^/]+)/(:any)'] = "$2/$1/$3/";
?>

Goal:
Rewrite: domein/fr/controller/method/any to domein/controller/method/fr/any.
#4

[eluser]Ki[/eluser]
I ended up going with an easier solution of adjusting all my routes to

$route["^$key/(.+)"] = "$1";

and then doing redirects within each controller as needed. Ended up being exactly what I wanted with each controller handing their own redirection internally.




Theme © iAndrew 2016 - Forum software by © MyBB