Im wondering if someone could help me out.
Currently to view a users profile in my codeigniter app, the url is as follows:
http://www.website.com/profile/u/username
I would like to change this to read
http://www.website.com/username
Is this possible using routes? if so could someone give me a bit of advice how to do it?
Also, if someone signs up a username that is the same as a controller name, what would happen then?
Cheers,
1. Is this possible using routes?Yes.
2. If so could someone give me a bit of advice how to do it?Sure:
$route['(:any)'] = "profile/u/$1";More info: http://codeigniter.com/user_guide/general/routing.html
3. Also, if someone signs up a username that is the same as a controller name, what would happen then?You should not allow an user to sign up using a username like that. Facebook does this! (www.facebook.com/groups/123457890 = “groups” can’t be used as username)
To avoid that an access to a controller is routed into a profile access, you should add a routing config prior to the one mentioned above, like this:
$route['(admin|groups|signup)'] = "$1";Here we have a regular expression, easy to understand. You just need to separate your controller names with the vertical bar character.
I hope this helps!