I'm creating a search results page using the Search API. I want to set an url like this:


How should i set up my route? It must accept any combination of characters, including non-ascii, spaces, numbers, etc, but it must not be empty.

This is my current routing rule. As you can see, there is no restriction for the text parameter:

      path: '/search/{text}'
        text: NULL
        _controller: '\Drupal\my\Controller\SearchController::results'
        _title: 'Search Results'
        _permission: 'access content'
  • I think you might want to set text to \w+, but I am not 100% certain. See: symfony.com/doc/current/routing/requirements.html Plus, it should go under requirements. – Kevin Jul 10 '17 at 17:10
  • 2
    Symfony placeholders are required unless told otherwise - just remove the default value? – Clive Jul 10 '17 at 17:12
  • \w+ will fail if there is a space (%20) between words. Removing the default value will do the trick. – José Trindade Jul 10 '17 at 17:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.