Jump to:

23360 Posts in 18124 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » Getting URLs Under a Page to Return 404 File Not Found

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: 1257 Views
  • Ben Gribaudo
    Avatar
    Community Member
    181 Posts

    Getting URLs Under a Page to Return 404 File Not Found Link to this post

    Hello,

    With a fresh install of SilverStripe, the "About Us" page is located at: http://localhost/about-us/
    Going to any of the following URLs results in the "About Us" page being displayed instead of a 404 file not found error:
    http://localhost/about-us/abc/
    http://localhost/about-us/abc/abc/
    http://localhost/about-us/abc/abc/abc/

    The reason this happens is that the rounting process knows that the page is displayed by a controller and thinks that the "/abc" parts of the URL are route parameters matching to "$Action/$ID/$OtherID" in the routing rules.

    This functionality makes sense if we are writing a complex controller, but when we're just serving up normal site pages, a 404 response seems appropriate to return for the "/abc" URLs. It seems like this would be the desired default behavior for Page_Controller (i.e. made a part of core).

    What do y'all think?

    One way to implement this--in Page_Controller:

       function handleRequest($request) {
          $action = $request->latestParam('Action');
          // if the Action param is set but the controller doesn't have a method to handle that action, display a 404 error
          if ($action && !$this->hasMethod($action)) {
             // dispaly the 404 file not found error message
          }
          
          return parent::handleRequest($request);
       }

    Btw, what is the best way to display a 404 error page from the method above?

    Thank you,
    Ben

  • ajshort
    Avatar
    Community Member
    244 Posts

    Re: Getting URLs Under a Page to Return 404 File Not Found Link to this post

    I fixed this as part of the nestedurls branch already, which will most probably be merged back for 2.4 - see http://open.silverstripe.org/changeset/64140

  • Ben Gribaudo
    Avatar
    Community Member
    181 Posts

    Re: Getting URLs Under a Page to Return 404 File Not Found Link to this post

    Thanks for that tip, Andrew. I am really looking forward to when nestedurls becomes a part of core. Here, we're already building a couple of sites that use it, with plans to go live with them even though nestedurls is still in beta.

    1257 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.