regex problem in routes. |
[eluser]Zeeshan Rasool[/eluser]
As i found in CI manual Code: $routes['funcOne/:any'] = "site/funcOne/$1" Code: (.*) Code: :any i have same routes file for admin and site to control url for site i write something like that Code: $routes['(.*)/funcTwo'] = "site/funcOne/" site/second/funcTwo the above command also executes for this. It means (.*) assumes first two segments site/second as a single and redirects it to site/funcOne why? Thanks
[eluser]rogierb[/eluser]
(.*) is a regex that gets everything. So it does not matter if there are one, two or three segment. It just allows for everyting. Edit: try something like ([a-z]*){1}/funcOne
[eluser]Zeeshan Rasool[/eluser]
thanks ! you mean if i use .*/funcOne then it assumes all param single that come before funcOne? i-e if we have Code: $routes["(.*)/funcOne"] = site/funcOne; Code: site/test/funcOne above all three function will go to site/funcOne as we given?
[eluser]rogierb[/eluser]
Quote:above all three function will go to site/funcOne as we given? Yeah, it does.
[eluser]BrianDHall[/eluser]
For extra regex help on this sort of thing: http://www.regular-expressions.info/ You might consider a regex like this: [^/]+/funcOne(.*) That means "everything that is not /, as many as you can get, which is to be then immediately followed by /funcOne...then grab everything you can after that". This will work on anything with something/funcOne anywhere in the url and redirect it to site/funcOne. However, wouldn't you want parameters to that function redirect as well? Then perhaps this: Code: $routes["[^/]+/funcOne(.*)"] = "site/funcOne/$1"; The $1 holds anything caught inside the first set of parens and sticks it on the end of the reroute. One 'extra feature' is that this rule would still reroute a request like /test/controller/site/funcOnedontreroute and reroute it as site/funcOne/dontreroute Other than that it's perfectly alright ![]() |
Welcome Guest, Not a member yet? Register Sign In |