Search code examples
phproutescodeigniter-url

CodeIgniter Routing Difference?


A quick question, that I can't seem to find the answer to anywhere to do with routing in CI - is there any real difference between the global catch all:

$route['(.*)'] = 'controller';

and

$route['(:any)'] = 'controller';

I don't have any problems with my routing and either seems to work the same, but was just wondering if one way was better than the other.


Solution

  • OK, after digging into the Router class it seems that (:any) is a CodeIgniter expression which gets converted into the regex expression:

    .+
    

    This is different to using (.*) which is of course a regex expression. So the difference therefore is between:

    .+
    

    and

    .*
    

    The + matches the previous character 1 or more times, whereas * matches the previous character 0 or more times. Given the previous character is . (any character), this essentially means the same thing in the context it's being used. Hope that's helpful for somebody else too.