I'd like users registering on my website are redirected to the page where they clicked the "create account" button which is in a modal.

First, I tried to redirect to an absolute url I tried


I tried

$_REQUEST['destination'] = '<front>';

I tried this too :

$response = new \Drupal\Core\Routing\TrustedRedirectResponse('http://www.google.be');

I'm always redirected to /user/[uid]/edit

2 Answers 2


You could use Rules module to achieve that..

  • Does Rules module allow to go to the previous page ?
    – lbogdan
    Jun 15, 2017 at 12:59
  • A page redirect can be done to "a drupal path, path alias or external URL"
    – dharma
    Jun 15, 2017 at 13:25
  • 1
    @dharma true for D7, but I would really, really, repeat really, want to see an improved version of your answer that explains HOW to do this with Rules in D8 ... Jun 15, 2017 at 14:51

You can accomplish this with the Rules Link module, and using the php variable php variables %server[HTTP_REFERER]

Or, without having to enable php in rules, you can use a custom 'previous page' token, explained in this drupal.org issue.

Create a rule that triggers when the link is clicked, stores the previous page a a variable, do some other actions you want and at the end a redirect action to that previous page variable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.