What I want to do is if I got duplicate name routes,I just use one route instead using 3 routes, but I not sure what regular expression I need to use, any suggestion?
now I have this
product_test_1.html
product_test_2.html
product_test_3.html
my codeigniter routes
$route['product_test_1.html'] = "website/product";
$route['product_test_2.html'] = "website/product";
$route['product_test_3.html'] = "website/product";
something what I want (but its not working)
$route['/product_test/i'] = "website/product";
Any idea solve my problem ? thanks
Try this:
$route['product_test_[0-9]+\.html'] = 'website/product';
This is about specific as you can get. The [0-9] means any numerical digit (could also be \d) and the + means 1 or more of the preceding token (the numerical digit).
If you want to capture just anything, the . token is "any character", so you can replace [0-9]+ with .+, which means it will match a string of (pretty much) any character that is 1 or longer.
This creates duplicate urls for the same page, which isn't normally desirable, but maybe you specifically want that. If not, you may consider 301 redirects via .htaccess.
You could also pass in the ID to the function with this if that is what you are going for.
$route['product_test_([0-9]+)\.html'] = 'website/product/$1';
The parenthesis captures the number and we pass it to the URL with $1 since it was the first capturing match captured.
Then, in you website controller, you could declare your product method as such:
function product($id)
And $id will automagically be the ID we passed in the URL taken from the product_test_#.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With