Jump to:

23368 Posts in 18143 Topics by 2863 members

General Questions

SilverStripe Forums » General Questions » create clean url for member or user page

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 553 Views
  • urd1
    Avatar
    Community Member
    9 Posts

    create clean url for member or user page Link to this post

    Hi,
    I really need help for my projects.
    Introduce, I've been using silverstripe for about 4 years.
    I also had searching of this question but still cant find the answer.

    I want to make clean url for member/user page, from:
    - www.mydomain.com/user/adam
    - www.mydomain.com/user/bob
    - www.mydomain.com/user/chris

    To:
    - www.mydomain.com/adam
    - www.mydomain.com/bob
    - www.mydomain.com/chris

    Should I edit the .htaccess or using $url_handlers on my Page Controller?

    Thx and Regards,
    Silverstripe Developer from Indonesia
    www.crosstechno.com

  • urd1
    Avatar
    Community Member
    9 Posts

    Re: create clean url for member or user page Link to this post

    anyone?

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: create clean url for member or user page Link to this post

    Unless you knew all the member users and hard coded each in your .htaccess, the best method is to use a custom handleAction() method to check for a member of that username (https://github.com/silverstripe/sapphire/blob/3.0/control/Controller.php#L185)

    I should clarify, don't edit that file directly. You can create your custom handleAction in Page_Controller (and use parent::handleAction() to refer to the original function)

  • urd1
    Avatar
    Community Member
    9 Posts

    Re: create clean url for member or user page Link to this post

    Hi Willr,

    Thx for your answer.
    I've tried that, but still doesn't work.

    in the first line of handleAction method:

    foreach($request->latestParams() as $k => $v) {
    if($v || !isset($this->urlParams[$k])) $this->urlParams[$k] = $v;
    }

    for example if the URL is: www.mydomain.com/adam
    if we debug the $request or $request->latestParams(), we will never get value of "adam"
    $request->latestParams() will return: Action = NULL, ID = NULL, OtherID = NULL

  • kinglozzer
    Avatar
    Community Member
    138 Posts

    Re: create clean url for member or user page Link to this post

    urd1,

    I've just been testing this on a site I'm building where I need to remove 'view' from 'xyz.com/projects/view/example-project', in handleAction(), the info I needed ('example-project') was found by doing:

    $request->param('Action')

    For your example, I believe SilverStripe will think that 'adam' is the action, so you can then check for the existence of a user, then if they don't exist simply call parent::handleAction();

    EDIT:

    Sorry I've just re-read your post and you aren't getting an action returned. I don't know if it acts differently as you're trying to get the request from the home page, do you have any URL handlers set up or anything that could possibly affect it?

  • urd1
    Avatar
    Community Member
    9 Posts

    Re: create clean url for member or user page Link to this post

    Hi kinglozzer,
    thx for your answer.

    I already knew and i already re-tested your example on my project, still doesn't work.
    Your answer is working on the other page except home.
    - www.mydomain.com/user/adam => "URLSegment" = about, "Action" = adam
    - www.mydomain.com/adam => "URLSegment" = NULL, "Action" = NULL
    Can you check again on your project in the home URL?

    What i want is:
    - www.xyz.com/example-project, not www.xyz.com/projects/example-project
    - "example-project" is dynamic value, not some of Page / Page Controller
    - "projects" is Page / Page Controller and I don't need that

    Thx anyway

    553 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.