Reputation: 4343
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,
Upvotes: 1
Views: 236
Reputation: 600
this link could help you : http://ellislab.com/forums/viewthread/186025/
you can do as it said.
or
you must use apache rewrite module and use .htaccess first
RewriteEngine on
RewriteCond $1 !^(index\.php|(.*)\.swf|forums|images|css|downloads|jquery|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?$1 [L,QSA]
and delete index.php from applications/config/config.php
$config['index_page'] = "index.php"; and route with
$route['^(?=[^\s]*?[0-9])(?=[^\s]*?[a-zA-Z])[a-zA-Z0-9]*$'] = "user/$1";`
Upvotes: 0
Reputation: 20492
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!
Upvotes: 3