Custom redirect to an url with "+" I use search api module and a view of products. If I put the search text block and I do a search, It redirect to an url like this: 
 &lt;my domain&gt;?search_api_fulltext=word1+word2+word3&amp;sort_by=title_1&amp;sort_order=ASC 

Where all search words are separated by a plus sign ("+").
I have my custom search block and I want to redirect to the same url in the submit function of the form. This is my code:

public function submitForm(array &amp;$form, FormStateInterface $form_state) {

if (!empty($form_state-&gt;getValue('textBox'))) {      
  $text = str_replace(' ', '+', $form_state-&gt;getValue('textBox'));
  $option = [
    'query' =&gt; ['search_api_fulltext' =&gt; $text, 
                'sort_by'=&gt;'search_api_relevance', 
                'sort_order'=&gt;'ASC'],
  ];
  $url = Url::fromUri('internal:/shop', $option);
  $form_state-&gt;setRedirectUrl($url);      
}
return;


}  

But it redirect to &lt;my domain&gt;?search_api_fulltext=word1%2Bword2&amp;sort_by=title_1&amp;sort_order=ASC, where plus signs are replaced with %2B, and then, the search is incorrect.
How could I avoid this replacement?
The URL you're building is taking the query (e.g. "word1 word2 word3") and replacing it with literal "+" chars for spaces. Hence, the %2B encoding in the string.

You don't need to parse/encode $form_state-&gt;getValue('textBox'). Per the documentation of Url::fromUri() for the $options param:


  
  'query': An array of query key/value-pairs (without any URL-encoding) to append to the URL.
  


$options['query'] expects its key/value pairs to have the literal strings.

You needn't worry about +/%20 encoding differences. They are different ways to encode the space character. (the + is an older space-encoding spec which you can do if absolutely needed, see rawurlencode, urlencode, &amp; http_build_query in the PHP docs).