How do I create a route with a query string? I have tried a few things and I cannot manage to make this working.

My route is the following.

    amu_hal.publicationsPerYear:
      path: '/publications/{year}'
      defaults:
        _controller: '\Drupal\amu_hal\Controller\AmuHalController::publicationPerYear'
        _title: 'publicationPerYear'
        year: 2016
        route_parameters:
          url: 'default'
      requirements:
        _permission: 'access content'


The code for the controller is the following.

    public function publicationPerYear($year,$url) {
      $url=urldecode($url);
      $url .='&amp;fq=producedDateY_i:' . $year;

      try {
        $client = new Client();
        $response = $client-&gt;request('GET', $url);
        $content = json_decode($response-&gt;getBody(), true);
        // ...
      }
    }


The request http://mysite/publications/2016?url=https%3A%2F%2FmyWS%2Fsearch%2F%3Frows%3D5%26sort%3DproducedDate_tdate%2Bdesc%26fl%3Dtitle_s%2Cen_title_s%2Clabel_s%2Cen_label_s%2CdocType_s%2CauthIdHal_s%2ChalId_s%2CstructId_i%2Curi_s%2Ckeyword_s%2Cen_keyword_s%2CauthLastNameFirstName_s%2CjournalTitle_s%26fq%3DauthFullName_t%3A(%22M%22+OR+%22e+d%22) gives the following error:


  RuntimeException: Controller "Drupal\amu_hal\Controller\AmuHalController::publicationPerYear()" requires that you provide a value for the "$url" argument (because there is no default value or because there is a non optional argument after this one). in Drupal\Core\Controller\ControllerResolver->doGetArguments() (line 165 of /var/aegir/platforms/drupal8-dev/core/lib/Drupal/Core/Controller/ControllerResolver.php).
You cannot create a route based on the query string, but you still can retrieve query string values in your code:

amu_hal.publicationsPerYear:
  path: '/publications/{year}'
  defaults:
    _controller: '\Drupal\amu_hal\Controller\AmuHalController::publicationPerYear'
    _title: 'publicationPerYear'
    year: 2016
  requirements:
    _permission: 'access content'




public function publicationPerYear($year) {
  $url = \Drupal::request()-&gt;query-&gt;get('url') ?: 'default';
}