From 1a60aeac2e62778558b34032e50b4ef4b1fddaa0 Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Mon, 14 Jul 2014 11:02:20 +0000 Subject: [PATCH] Remove trailing slash if it exists in a request Fixes #36 --- src/mibew/configs/routing.yml | 10 +++++ .../Mibew/Controller/RedirectController.php | 41 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 src/mibew/libs/classes/Mibew/Controller/RedirectController.php diff --git a/src/mibew/configs/routing.yml b/src/mibew/configs/routing.yml index 7c326a43..e2e4219e 100644 --- a/src/mibew/configs/routing.yml +++ b/src/mibew/configs/routing.yml @@ -673,3 +673,13 @@ users_update: defaults: _controller: Mibew\Controller\UsersController::updateAction _access_check: Mibew\AccessControl\Check\LoggedInCheck + +# Remove trailing slashe. This route is the last one because previous rotes can +# (but definitely should not) have trailing slashes. +remove_trailing_slash: + path: /{url} + defaults: + _controller: Mibew\Controller\RedirectController::removeTrailingSlashAction + requirements: + url: .*/$ + methods: [GET] diff --git a/src/mibew/libs/classes/Mibew/Controller/RedirectController.php b/src/mibew/libs/classes/Mibew/Controller/RedirectController.php new file mode 100644 index 00000000..3004a0b8 --- /dev/null +++ b/src/mibew/libs/classes/Mibew/Controller/RedirectController.php @@ -0,0 +1,41 @@ +getPathInfo(); + $request_uri = $request->getRequestUri(); + $url = str_replace($path_info, rtrim($path_info, ' /'), $request_uri); + + return $this->redirect($url, 301); + } +}