Skip to content

Commit

Permalink
FIX don't add trailing slash to external redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
lekoala committed Feb 28, 2024
1 parent 4f3282b commit 21c9c13
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Control/RequestHandler.php
Expand Up @@ -598,7 +598,10 @@ public function AbsoluteLink($action = '')
*/
public function redirect(string $url, int $code = 302): HTTPResponse
{
$url = Director::absoluteURL($url);
// Attach site-root to relative links, if they have a slash in them
if ($url == "" || $url[0] == '?' || (!str_starts_with((string) $url, "http") && $url[0] != "/" && str_contains((string) $url, '/'))) {
$url = Director::baseURL() . $url;
}
$response = new HTTPResponse();
return $response->redirect($url, $code);
}
Expand Down

0 comments on commit 21c9c13

Please sign in to comment.