Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

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

  • hgtonighthgtonight ∞ · New Moderator
    Answer ✓

    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.

    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.

Answers

  • R_JR_J Ex-Fanboy Munich Admin

    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.

  • hgtonighthgtonight ∞ · New Moderator
    Answer ✓

    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.

    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.

  • @R_J said:
    What would you do if some freak names himself "discussions" or "activity"?

    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.

  • @hgtonight said:
    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.

    Thank you this has been very insightful and helpful

Sign In or Register to comment.