Skip to content

BUGFIX: Redirect handler works with Neos in subdirectory #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Classes/RedirectService.php
Original file line number Diff line number Diff line change
@@ -13,9 +13,9 @@
* source code.
*/

use Neos\Flow\Http\ServerRequestAttributes;
use Neos\RedirectHandler\Storage\RedirectStorageInterface;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Http\Helper\RequestInformationHelper;
use Neos\Flow\Mvc\Routing\RouterCachingService;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
@@ -107,7 +107,8 @@ protected function buildResponse(ServerRequestInterface $httpRequest, RedirectIn
$location = $redirect->getTargetUriPath();

if (parse_url($location, PHP_URL_SCHEME) === null) {
$location = (string)$httpRequest->getUri()->withQuery('')->withFragment('')->withPath($location);
$baseUriForRequest = (string)RequestInformationHelper::generateBaseUri($httpRequest);
$location = rtrim($baseUriForRequest, '/') . '/' . ltrim($location, '/');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't be better to assure, that the $baseUriForRequest got from that method always has / has not a trailing slash?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, and actually that is the case. It always has a trailing slash

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we be sure that location has (or has not) a leading slash?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

targetUriPath gets a ltrim for slashes in it's constructor.

}

$response = $response->withHeader('Location', $location)