Search code examples
phpmysqlcodeignitercodeigniter-routing

Codeigniter: I would like create user URL's for my users when they create a username


I wold like to create this kind of URL for my users when they register a username mysite.com/username

I've search many posts on this site and I see people doing it like this mysite.com/user/username

I would like to get rid of the user and just have it go directly to mysite.com/username

What would be the best way to this?


Solution

  • I am not familiar with CodeIgniter but here is a general answer for why people don't use mysite.com/username:

    mysite.com/user/username is a good solution because usually the URL dispatcher passes username to a function/module that handles users' page.

    mysite.com/username is a bad solution because your dispatcher will have to have a greedy rule after all your other rules, to pass everything other that those previous rules to the module/function that handles users' page.

    Now suppose you want to use mysite.com/username and suppose you have mysite.com/logout which lands users to the logout page. A user comes and registers himself with "logout" as his username. Then how are you going to say by accessing mysite.com/logout Mr. logout wants to logout or wants to see his page?