Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Reduce the number of routing rules?
#5

[eluser]JayTee[/eluser]
It turns out that, like WanWizard mentioned, RegEx is definitely the way to go. The issue is the (:any) part of the RegEx. CodeIgniter's Router class converts ':any' to '.+' - which matches 1 or more of any character. So for this rule:
Code:
$route['(:any)/(.*)'] = "$2";
In plain English - that routing rule says:
"Match 1 or more of any character followed by a '/' followed by 0 or more of any character"
http://example.com/blah/controller -> $2 = 'controller'
http://example.com/blah/controller/method -> $2 = 'method' (404 error)
http://example.com/blah/controller/method/arg -> $2 = 'arg' (404 error)

The issue is because .+ matches everything before the last literal '/' character ('blah/controller' in the second url I listed)

To fix this, I changed the first part of the rule so that it only matches the 'word' characters of the first segment:
Code:
$route['(\w+)/(.*)'] = $2;
In plain English, the new rule says:
"Match 1 or more word characters followed by a '/' followed by 0 or more of any character"
By sticking to only "word" characters (A "word" character is any letter or digit or the underscore character), it doesn't match the first '/', so the rest of the rule works.

And with that single routing rule, I am able to ignore the first segment if all the URI's for my site.


Messages In This Thread
[SOLVED] Reduce the number of routing rules? - by El Forum - 10-25-2010, 11:47 AM
[SOLVED] Reduce the number of routing rules? - by El Forum - 10-25-2010, 12:15 PM
[SOLVED] Reduce the number of routing rules? - by El Forum - 10-25-2010, 12:22 PM
[SOLVED] Reduce the number of routing rules? - by El Forum - 10-25-2010, 12:39 PM
[SOLVED] Reduce the number of routing rules? - by El Forum - 10-25-2010, 12:58 PM



Theme © iAndrew 2016 - Forum software by © MyBB