Alter existing 'Log In' route so URL includes request_uri as query string I am trying to alter the existing 'Log In' URL so that it points to a certain location and also includes  the REQUEST_URI as a query string that is not encoded. How do I do this?
Based on this article, Altering existing routes and adding new routes based on dynamic ones and this SE answer I can change the 'Log In' URL so it points to a different location (/login). What I can't seem to figure out is how to add a query string that isn't encoded.
This code:
$route-&gt;setPath('/login?destination=' . \Drupal::request()-&gt;server-&gt;get('REQUEST_URI'));

Gives me:
/login%3Fdestination%3Dpage2

What I want is:
/login?destination=page2

I have looked into RequestContext::setQueryString and Route::addOptions but can't seem to get anything to work.
Full code:
&lt;?php
namespace Drupal\myModule\Routing;

use Drupal\Core\Routing\RouteSubscriberBase;
use Symfony\Component\Routing\RouteCollection;

/**
* Listens to the dynamic route events.
*/
class RouteSubscriber extends RouteSubscriberBase {

    /**
    * {@inheritdoc}
    */

    protected function alterRoutes(RouteCollection $collection) {
        // Change path '/user/login' to '/login'.
        if ($route = $collection-&gt;get('user.login')) {
            //$route-&gt;setPath('/login');
            $route-&gt;setPath('/login?destination=' . \Drupal::request()-&gt;server-&gt;get('REQUEST_URI'));

        }
        
        // Always deny access to '/user/logout'.
        // Note that the second parameter of setRequirement() is a string.
        if ($route = $collection-&gt;get('user.logout')) {
            $route-&gt;setRequirement('_access', 'FALSE');
        }
    }
}
I think you'll need to have a look to PathProcessors, you might do something like that:
mymodule/mymodule.services.yml
mymodule.path_processor:
  class: Drupal\mymodule\PathProcessor\MymodulePathProcessor
  tags:
    - { name: path_processor_inbound, priority: 250 }

mymodule/src/PathProcessor/MymodulePathProcessor
&lt;?php

namespace Drupal\mymodule\PathProcessor;

use Drupal\Core\PathProcessor\InboundPathProcessorInterface;
use Symfony\Component\HttpFoundation\Request;

/**
 * Class MymodulePathProcessor.
 *
 * @package Drupal\mymodule\PathProcessor
 */
class MymodulePathProcessor implements InboundPathProcessorInterface {
  
  /**
   * {@inheritdoc}
   */
  public function processInbound($path, Request $request) {
    if ($path == '/user/login') {
      $request_uri = $request-&gt;server-&gt;get('REQUEST_URI');
      return &quot;/login?destination={$request_uri}&quot;;
    }
  }
}

Don't forget to clear the cache before to try it.
You might need the processOutbound function too in which case you'll need one more line in your service
mymodule/mymodule.services.yml
mymodule.path_processor:
  class: Drupal\mymodule\PathProcessor\MymodulePathProcessor
  tags:
    - { name: path_processor_inbound, priority: 250 }
    - { name: path_processor_outbound, priority: 250 }