I need to build an external URL that looks like this:
First thought is that /#/ is entirely invalid according to RFC 3986, unless I'm reading it incorrectly, but that's what I've been given. So I'm building it like so:
$base_url = 'https://searchapp.foo.gov/search-org/#/collection-name'; $options = [ 'absolute' => TRUE, 'https' => TRUE, 'query' => [ 'q' => $form_state->getValue('search'), ], ]; $url = Url::fromUri($base_url, $options)->toString();
Instead of the expected output, I find that my querystring is appearing before the #:
I've tried using /%23/ instead of /#/, and that fixes the problem with the querystring being out of place, but creates a new problem by url encoding the %, so that I wind up with /%2523/.
I'm guessing this is a problem with hash segment handling. Is there a right way to handle a URL like this?