Normally when you expect an "internal path" you don't need to start with a /. For example, to redirect to node 1 I would use a url of "node/1". However, when I do this it tries to redirect me to /user/node/1.

You might want to do something like this:

$url_object = \Drupal::service('path.validator')->getUrlIfValid($path);
$url_object->setAbsolute();
$url = $url_object->toString();

to validate and get the correct internal path.

Also, when doing the redirect, you should probably use a status of 302, like:

$response = new RedirectResponse($url, 302);

CommentFileSizeAuthor
#3 2803235-3.patch580 bytesneerajskydiver
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mpotter created an issue. See original summary.

gdelver@xs4all.nl’s picture

Same issue here, cannot get it working in whatever way I define the path (using local dev environment)
@mpotter: Question: shouldn't it be something like "/node/1" like you do in the basic system settings for the landing page and elsewhere in D8?

neerajskydiver’s picture

FileSize
580 bytes

This will work for both with & without "/"

krknth’s picture

Status: Active » Reviewed & tested by the community

  • krknth committed 802658c on 8.x-1.x authored by neerajskydiver
    Issue #2803235 by neerajskydiver, mpotter, gdelver@xs4all.nl, krknth:...
krknth’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.