0

Normally in Codeigniter a url by default has two to three segments like this. http://www.yoursite.com/controller/function

My question is, can I replace that function segment for a value if my code is in the index part of the controller.

I have a controller for just user profiles and I'm trying to make that the simplest url possible, so it's easily sharable. For example I would like the url to be something like this http://www.mywebsite.com/author/zazvorniki instead of having to call a function like this. http://www.mywebsite.com/author/user/zazvorniki

Is this possible? Is there a setting I can change to make this possible?

zazvorniki
  • 3,512
  • 21
  • 74
  • 122
  • maybe of help ... http://ellislab.com/codeigniter/user-guide/general/routing.html – Orangepill Jun 17 '13 at 02:45
  • I was looking at that, but it seems that if you set a routing rule that it will affect all the url's instead of just one controller...am I reading that right? I'm kind of afraid I'm going to mess everything up... – zazvorniki Jun 17 '13 at 02:50
  • it will only effect those urls that are prefixed with the controller slug (i.e. /author/) – Orangepill Jun 17 '13 at 02:54
  • ok, but if I do a rout like this $route['author'] = "author/"; how do I plug in the user's name to pull up the right profile? – zazvorniki Jun 17 '13 at 02:58
  • Answer shows the route rule that should be added. – Orangepill Jun 17 '13 at 03:03

1 Answers1

2

Just add the following route rule.

 $route['author/(:any)'] = "author/user/$1";
Orangepill
  • 24,500
  • 3
  • 42
  • 63
  • I'm sorry for being so dense, but this still isn't making any sense to me. When I follow the rule you posted I'm still getting back a 404 error page because it seems like it's still looking for a function where the username is. – zazvorniki Jun 17 '13 at 03:09
  • just for a test change the rule to ` $route['authors/(:username)'] = "author/user/$1";` so it won't conflict with the existing author controller route – Orangepill Jun 17 '13 at 03:17
  • Thank you! I figured it out, for some reason it didn't like the :username, but it accepted :any. – zazvorniki Jun 17 '13 at 03:19
  • 1
    I'll change answer to reflect this – Orangepill Jun 17 '13 at 03:20