Welcome Guest, Not a member yet? Register   Sign In
URL path aliasing

[eluser]Bacteria Man[/eluser]
I would like to implement URL path aliasing for accessing user profiles.

For example when accessing my user profile


the URL path would be instead


where a regular expression would shift all alpha letters to lower case and replace the space with an underscore. Other unfriendly characters would either be converted accordingly or disallowed completely when defining a user name.

Since the system will eventually have 1000's of users it's obviously not practical nor efficient to predefine routes for all of these associations.

I'm wondering (at least for my specific need) if it would be easier to simply store the alias in the user profile and query against the alias (which, based on the user name, is unique) instead of the ID.

Is there a more elegant or better way to go about this? All comments/suggestions greatly appreciated.

[eluser]Bacteria Man[/eluser]
A quick follow-up.

Instead of using my own regular expression Code Igniter already includes the handy helper function url_title(), which converts a user inputted string to URL-friendly one.

[eluser]Michael Wales[/eluser]
You pretty much have it down - that's the exact way I do it. Do some URL Routing to map /members/ to the method you want, store the user's username in the database as a slug (with url_title()), then query the database for uri->segment(2) whenever someone hits that method.

[eluser]Bacteria Man[/eluser]
Yes, a slug--exactly.

Thanks for the confirmation.

Theme © iAndrew 2016 - Forum software by © MyBB