Reputation: 402
I wanted to convert my website old URL's to new URL's and here is my old URL's and routing code:-
1) www.mysite.com/physics/basics-of-physics
2) www.mysite.com/physics/what-is-newtons-first-law-in-physics
3) www.mysite.com/chemistry/basics-of-chemistry
4) www.mysite.com/biology/basics-of-biology
Below is the routing code I am using for the above URLs is:-
$route['physics/(:any)'] = "Physics/index/$1";
$route['chemistry/(:any)'] = "Chemistry/index/$1";
$route['biology/(:any)'] = "Biology/index/$1";
And here is new(actual) url's
1) www.mysite.com/basics-of-physics
2) www.mysite.com/what-is-newtons-first-law-in-physics
3) www.mysite.com/basics-of-chemistry
4) www.mysite.com/basics-of-biology
The simple logic I am using here is,
1st and 2nd URL's data stored in tbl_physics table and I am using Physics.php as a controller.
3rd URL data stored in tbl_chemistry table and I am using Chemistry.php as a controller.
4th URL data stored in tbl_physics database table and I am using Biology.php as a controller.
Here is the code what I tried
$route['(:any)'] = "Physics/index/$1";
$route['(:any)'] = "Chemistry/index/$1";
$route['(:any)'] = "Biology/index/$1";
But all the URLs are pointing to the Biology.php controller. What modifications do I need to do in the above code?
Upvotes: 0
Views: 79
Reputation: 8964
The var $route
is an array. You have assigned three different values to the array key '(:any)'
. Naturally, the value of $route['(:any)']
will be the last value assigned, i.e. "Biology/index/$1"
. That is why the Biology
controller is always used.
You can use regular expressions to define route rules. (See this) That's what you need to explore in order to define distinct routes for each URL you have in mind.
Upvotes: 0