Skip to content

Instantly share code, notes, and snippets.

@josevh
Last active April 23, 2022 15:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josevh/6edfd024b12dcbb7701f4c61736e06d4 to your computer and use it in GitHub Desktop.
Save josevh/6edfd024b12dcbb7701f4c61736e06d4 to your computer and use it in GitHub Desktop.
Remove trailing slashes in FlightPHP url's
<?php
// before any other route
Flight::route('*', function () {
$request = Flight::request();
if ($request->url != '') {
list($base, $query) = array_pad(explode('?', $request->url, 2), 2, null);
if (substr($base, -1) == '/' && strlen($base) > 1) {
$url = rtrim($base, '/');
if ($query !== null) {
$url .= '?' . $query;
}
Flight::redirect($url, 301);
return false;
}
}
return true;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment