Skip to content

Commit

Permalink
Match slashed URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
Hlavtox committed Jun 13, 2024
1 parent 2937cae commit 6b38d47
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions classes/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,20 @@ public function computeRoute($rule, $controller, array $keywords = [], array $pa
$keywords = $transform_keywords;
}

/*
* Now, we will add one optional / to the end of the regexp. This will allow to match
* both slashed and non-slashed variant of the URL. The user will be automatically redirected
* to the proper canonical variant in the controller, but he won't get a 404.
*/
if (substr($regexp, -1) == '/') {
// If the expression ends with a slash, we make it optional.
$regexp .= '?';
} else {
// If not, we add the optional slash.
$regexp .= '/?';
}

// Add some static rules to the regexp for all routes
$regexp = '#^/' . $regexp . '$#u';

return [
Expand Down

0 comments on commit 6b38d47

Please sign in to comment.