Welcome Guest, Not a member yet? Register   Sign In
WP like URI routing
#1

[eluser]lerio[/eluser]
Hi everyone,

I need to know if is there a way to change this:

http://my_site.com/my_class/my_method/my_parameter

to this:

http://my_site.com/my_paramenter

I know this may sound crazy but that's what WP does for its articles and I need to do that on CI for SEO reasons.

Thanks in advance
#2

[eluser]Jelmer[/eluser]
You can always send everything to a single controller:
Code:
$route[':any'] = 'controller';

But if you do that you'll have to add every other controller specificly BEFORE that rule:
Code:
$route['other_controller(/:any)?'] = 'other_controller$1';

EDIT: correction to the other_controller rule (forgot the question mark)
#3

[eluser]lerio[/eluser]
I'll try it.

thank you so much!
#4

[eluser]Jelmer[/eluser]
Hmm, just a quick correction: I forgot the quesion mark at the end of the $route for other controllers:
Code:
$route['other_controller(/:any)?'] = 'other_controller$1';

As such it will work both when yourdomain.com/other_controller is requested, and when yourdomain.com/other_controller/somefunction is requested. The previous route would only work on the second example but not on the first (controller without explicit function).
#5

[eluser]lerio[/eluser]
Thanks, that worked.

This is how I obtained WP-like URIs with CodeIgniter, like:

http://www.my-site.com/my-article
http://www.my-site.com/tag/my-tag
http://www.my-site.com/category/my-category

open config/routes.php and add the following lines:

Code:
$route['tag/(:any)?'] = 'my-controller-1/my-method-/$1';
$route['cat/(:any)?'] = 'my-controller-2/my-method-2/$1';
$route['(:any)?'] = 'my-controller-3/my-method-3/$1';

like said before, order is very important.

Thanks again




Theme © iAndrew 2016 - Forum software by © MyBB