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