Last active
April 23, 2022 15:00
-
-
Save josevh/6edfd024b12dcbb7701f4c61736e06d4 to your computer and use it in GitHub Desktop.
Remove trailing slashes in FlightPHP url's
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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