Welcome Guest, Not a member yet? Register   Sign In
[SOLVED!] Friendly URL and removing controller name?
#6

[eluser]Michael Wales[/eluser]
The only thing you need to watch out for are other potential URLs that could meet the requirement for this rule. If you come across those - simply define a stricter rule prior to this catch-all rule. The following example makes little sense (SEO-wise), but proves the point:

domain.com/admin/4/edit would qualify for the catch-all rule, pointing it to Page->view(4) - obviously not what we want. We want it to go to Admin->edit_users() - here's how to correct:

Code:
$route['admin/:num/:any'] = 'admin/edit_users';
$route['([a-z0-9-_]+)/([0-9]+)/([a-z0-9-_]+)'] = 'page/view/$2';

Like I said, the example itself makes little sense.

The most common place I use these catch-all style routing is when I want to use a domain.com/username style of URL for member profiles. I define all of my known routes, then a catch-all route for anything else.
Code:
$route['signup'] = 'users/signup';
$route['login'] = 'users/login';
$route['admin/write'] = 'admin/new_post';
$route['admin/manage/([0-9]+)'] = "admin/edit_post/$3"; // Admin->edit_post($id = null)
$route['admin/manage'] = 'admin/edit_post';
$route['([a-z0-9-_]+)'] = "users/view/$1"; // Users->view($username = null)


Messages In This Thread
[SOLVED!] Friendly URL and removing controller name? - by El Forum - 01-21-2008, 11:00 PM
[SOLVED!] Friendly URL and removing controller name? - by El Forum - 01-22-2008, 12:20 AM
[SOLVED!] Friendly URL and removing controller name? - by El Forum - 01-22-2008, 10:20 AM
[SOLVED!] Friendly URL and removing controller name? - by El Forum - 01-22-2008, 10:59 AM
[SOLVED!] Friendly URL and removing controller name? - by El Forum - 01-22-2008, 11:52 AM
[SOLVED!] Friendly URL and removing controller name? - by El Forum - 01-22-2008, 12:02 PM
[SOLVED!] Friendly URL and removing controller name? - by El Forum - 01-22-2008, 05:28 PM
[SOLVED!] Friendly URL and removing controller name? - by El Forum - 01-28-2008, 06:48 PM



Theme © iAndrew 2016 - Forum software by © MyBB