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:
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.
The parenthesis captures the number and we pass it to the URL with
$1since it was the first capturing match captured.Then, in you
websitecontroller, you could declare yourproductmethod as such:And
$idwill automagically be the ID we passed in the URL taken from theproduct_test_#.html