diff --git a/control/Director.php b/control/Director.php index c7337de93..a1ef3b0e4 100644 --- a/control/Director.php +++ b/control/Director.php @@ -331,6 +331,9 @@ class Director implements TemplateGlobalProvider { } } } + + // No URL rules matched, so return a 404 error. + return new SS_HTTPResponse('No URL rule was matched', 404); } /** diff --git a/tests/control/DirectorTest.php b/tests/control/DirectorTest.php index 4d1ccae17..bffe804c6 100644 --- a/tests/control/DirectorTest.php +++ b/tests/control/DirectorTest.php @@ -281,6 +281,10 @@ class DirectorTest extends SapphireTest { $this->assertEquals($headers, Director::extract_request_headers($request)); } + public function testUnmatchedRequestReturns404() { + $this->assertEquals(404, Director::test('no-route')->getStatusCode()); + } + } class DirectorTestRequest_Controller extends Controller implements TestOnly {