Welcome Guest, Not a member yet? Register   Sign In
routing and regular expressions
#1

[eluser]aeternuslibertas[/eluser]
Hi all I have a routes setting like this
Code:
$route['seo-descriptive-uri'] = 'controller';

however when I try accessing any of the functions in my controllerlike this -> mywebsite.com/seo-descriptive-uri/myfunction
it goes to the 404

I tried this to fix it like so:
Code:
$route['seo-descriptive-uri/^(.*)$'] = 'controller/$1';

but it still does not work, how can I allow code igniter to properly serve up the function ?
#2

[eluser]CroNiX[/eluser]
You need a route for each number of segments your controller and methods use (any parameters?), and they need to go in order from most specific (most segments) to the least because it will stop as soon as it finds a match.
Code:
$route['seo-descriptive-uri/(.*)/(.*)'] = 'controller/$1/$2';  //controller +2 variable segments
$route['seo-descriptive-uri/(.*)']      = 'controller/$1';  //controller +1 variable segment
$route['seo-descriptive-uri']           = 'controller'; //controller by itself, will go to index() method
#3

[eluser]aeternuslibertas[/eluser]
[quote author="CroNiX" date="1332359863"]You need a route for each number of segments your controller and methods use (any parameters?), and they need to go in order from most specific (most segments) to the least because it will stop as soon as it finds a match.
Code:
$route['seo-descriptive-uri/(.*)/(.*)'] = 'controller/$1/$2';  //controller +2 variable segments
$route['seo-descriptive-uri/(.*)']      = 'controller/$1';  //controller +1 variable segment
$route['seo-descriptive-uri']           = 'controller'; //controller by itself, will go to index() method
[/quote]

ohh ok I see, do you think that writing a URL rewrite in nginx would just be a more efficient option than using the routes in CI ?
#4

[eluser]CroNiX[/eluser]
I don't see how you could really rewrite the above to cover all 3 cases more efficiently, but it should work.




Theme © iAndrew 2016 - Forum software by © MyBB