为codeigniter中的url段传递的参数定义模式

I found a way to define a pattern to pass a parameter on url on codeigniter... I mean a pattern to make something like this:

www.example.com/part/of/url/parameter1/parameter2

I was needing pass a mac, so the pattern must to coincide with XX-XX-XX-XX-XX-XX, otherwise, the framework send a 404.
Well as I say I found a way to make this, but I don´t know if it is the best way. What I did is modified a file on the System folder... specifically the file: system/core/Router.php, I changed the default line 379 and put this other one:

 $key = str_replace(':any', '.+', str_replace(':num', '[0-9]+', str_replace(':mac', '[0-9A-Za-z]{2}-[0-9A-Za-z]{2}-[0-9A-Za-z]{2}-[0-9A-Za-z]{2}-[0-9A-Za-z]{2}-[0-9A-Za-z]{2}', $key)));

It works... but I would want to know if there is any way where I don´t need modify a file on the system folder... I have understood that it is not a good idea.

Thank you.

You can do it inside config/routes.php

for example:

$route['part/of/url/parameter1/([0-9A-Za-z]{2}-[0-9A-Za-z]{2}-[0-9A-Za-z]{2}-[0-9A-Za-z]{2}-[0-9A-Za-z]{2}-[0-9A-Za-z]{2})'] = 'my/routed/$1';

it will only route for urls that match your pattern. see http://www.codeigniter.com/user_guide/general/routing.html on section Regular Expressions

or, you could do this at the end of your routes.php.

$route['part/of/url/parameter1/(:mac)'] = 'my/routed/$1';


$temp = [];
foreach($route as $key => $value)
{
 $key = str_replace(':mac', '[0-9A-Za-z]{2}-[0-9A-Za-z]{2}-[0-9A-Za-z]{2}-[0-9A-Za-z]{2}-[0-9A-Za-z]{2}-[0-9A-Za-z]{2}', $key);
 $temp[$key] = $value;
}
$route = $temp;

to mantain a clean code, it's good to put this part on hooks, take a look at https://ellislab.com/codeigniter/user-guide/general/hooks.html

It's really important to mantain system files intact, because you will want to update codeigniter in the future.

just another way:

// my rules
$mac = '[0-9A-Za-z]{2}-[0-9A-Za-z]{2}-[0-9A-Za-z]{2}-[0-9A-Za-z]{2}-[0-9A-Za-z]{2}-[0-9A-Za-z]{2}';

$route["part/of/url/parameter1/($mac)"] = 'my/routed/$1';