open(1) to visit the URL. It seems if the URL is invalid (e.g., contains spaces),
open(1) will encode it before sending it to the web browser, for example, the command
~ $ open 'https://lwn.net/Articles/262464/#Quick Quiz 5'
opens https://lwn.net/Articles/262464/%23Quick%20Quiz%205 (404). However, if you the URL is valid, the
open(1) works fine, the command
~ $ open 'https://lwn.net/Articles/262464/#Quick%20Quiz%205'
opens https://lwn.net/Articles/262464/#Quick%20Quiz%205 (200).
I think you can avoid the issue by entering URL in the valid encoded format. It's also possible to fix the encoding automatically via the following advice
(:filter-args (args) fix-url)
"Fix URL encoding."
(cl-callf url-encode-url (car args))