diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index b064e729b8..0834bbfd25 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -350,6 +350,7 @@ phutil_register_library_map(array( 'PhabricatorProjectListController' => 'applications/project/controller/list', 'PhabricatorProjectProfile' => 'applications/project/storage/profile', 'PhabricatorProjectProfileController' => 'applications/project/controller/profile', + 'PhabricatorRedirectController' => 'applications/base/controller/redirect', 'PhabricatorRemarkupRuleDifferential' => 'infrastructure/markup/remarkup/markuprule/differential', 'PhabricatorRemarkupRuleManiphest' => 'infrastructure/markup/remarkup/markuprule/maniphest', 'PhabricatorRepository' => 'applications/repository/storage/repository', @@ -710,6 +711,7 @@ phutil_register_library_map(array( 'PhabricatorProjectListController' => 'PhabricatorProjectController', 'PhabricatorProjectProfile' => 'PhabricatorProjectDAO', 'PhabricatorProjectProfileController' => 'PhabricatorProjectController', + 'PhabricatorRedirectController' => 'PhabricatorController', 'PhabricatorRemarkupRuleDifferential' => 'PhutilRemarkupRule', 'PhabricatorRemarkupRuleManiphest' => 'PhutilRemarkupRule', 'PhabricatorRepository' => 'PhabricatorRepositoryDAO', diff --git a/src/aphront/applicationconfiguration/AphrontApplicationConfiguration.php b/src/aphront/applicationconfiguration/AphrontApplicationConfiguration.php index cadaaaa2e3..97b930e069 100644 --- a/src/aphront/applicationconfiguration/AphrontApplicationConfiguration.php +++ b/src/aphront/applicationconfiguration/AphrontApplicationConfiguration.php @@ -30,6 +30,7 @@ abstract class AphrontApplicationConfiguration { abstract public function getURIMap(); abstract public function buildRequest(); abstract public function build404Controller(); + abstract public function buildRedirectController($uri); final public function setRequest(AphrontRequest $request) { $this->request = $request; @@ -56,6 +57,15 @@ abstract class AphrontApplicationConfiguration { list($controller_class, $uri_data) = $mapper->mapPath($path); if (!$controller_class) { + if (!preg_match('@/$@', $path)) { + // If we failed to match anything but don't have a trailing slash, try + // to add a trailing slash and issue a redirect if that resolves. + list($controller_class, $uri_data) = $mapper->mapPath($path.'/'); + if ($controller_class) { + return $this->buildRedirectController($path.'/'); + } + } + return $this->build404Controller(); } diff --git a/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php b/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php index 269c7eba21..fe6fbb202f 100644 --- a/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php +++ b/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php @@ -368,5 +368,12 @@ class AphrontDefaultApplicationConfiguration return array(new Phabricator404Controller($this->getRequest()), array()); } + public function buildRedirectController($uri) { + return array( + new PhabricatorRedirectController($this->getRequest()), + array( + 'uri' => $uri, + )); + } } diff --git a/src/aphront/default/configuration/__init__.php b/src/aphront/default/configuration/__init__.php index 8fd005d1e7..e5d5554eff 100644 --- a/src/aphront/default/configuration/__init__.php +++ b/src/aphront/default/configuration/__init__.php @@ -12,6 +12,7 @@ phutil_require_module('phabricator', 'aphront/response/ajax'); phutil_require_module('phabricator', 'aphront/response/dialog'); phutil_require_module('phabricator', 'aphront/response/webpage'); phutil_require_module('phabricator', 'applications/base/controller/404'); +phutil_require_module('phabricator', 'applications/base/controller/redirect'); phutil_require_module('phabricator', 'applications/people/storage/user'); phutil_require_module('phabricator', 'view/dialog'); phutil_require_module('phabricator', 'view/page/failure'); diff --git a/src/applications/base/controller/redirect/PhabricatorRedirectController.php b/src/applications/base/controller/redirect/PhabricatorRedirectController.php new file mode 100644 index 0000000000..ad04a47407 --- /dev/null +++ b/src/applications/base/controller/redirect/PhabricatorRedirectController.php @@ -0,0 +1,31 @@ +uri = $data['uri']; + } + + public function processRequest() { + return id(new AphrontRedirectResponse())->setURI($this->uri); + } + +} diff --git a/src/applications/base/controller/redirect/__init__.php b/src/applications/base/controller/redirect/__init__.php new file mode 100644 index 0000000000..6b07af1d65 --- /dev/null +++ b/src/applications/base/controller/redirect/__init__.php @@ -0,0 +1,15 @@ +