Can you have a username url like this: mywebsite.com/myusername ?
I would like to put the username directly after the main domain url like on facebook and other social networks.
At the moment it runs off profile/username
Is it possible to remove the profile slug/breadcrumb and just have the username only on the end?
For example: mywebsite.com/myusername
Best Answer
-
hgtonight MVP
Garden (the framework Vanilla runs on) parses the URL during dispatch to figure out what controller to use. The word 'profile' tells Garden to start up the 'Profile' controller. You could hook into a dispatch that didn't find any result and do a username search on that.
Something like:
public function Gdn_Dispatcher_NotFound_Handler($Sender) { $PossibleName = $Sender->Request; $UserModel = new UserModel(); $User = $UserModel->GetByUsername($PossibleName); if($User) { $Sender->EventArguments['Handled'] = TRUE; Redirect(UserUrl($User)); return TRUE; } return FALSE; }
This does create overhead to every request destined to be a 404.
I would probably just create a short named controller that redirects to the profile controller. Something like
http://forums.example.com/u/UserName
.Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
3
Answers
What would you do if some freak names himself "discussions" or "activity"?
How would it magically detect a username form all the other places it has to go to?
Secondly what benefit do you think you are going to get from this?
grep is your friend.
Garden (the framework Vanilla runs on) parses the URL during dispatch to figure out what controller to use. The word 'profile' tells Garden to start up the 'Profile' controller. You could hook into a dispatch that didn't find any result and do a username search on that.
Something like:
This does create overhead to every request destined to be a 404.
I would probably just create a short named controller that redirects to the profile controller. Something like
http://forums.example.com/u/UserName
.Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
I would get the same benefit that Facebook, Twitter, foursquare, Reddit, and almost all other social networks get from keeping the url short with their username at the end.
Thank you this has been very insightful and helpful