How to Escape Hash Character in Url

How to escape hash character in URL

Percent encoding. Replace the hash with %23.

How to escape # symbol in url?

You would need to encode the parameters that may contain # and then decode back the parameter in server side code.

You can use many resources in the internet to URL-encode strings, like this. In your case, anil#1234 becomes anil%231234.

How to escape hash (#) characters in .htaccess?

Using the [B] flag should help in your case(available in Apache 2.2)

The [B] flag instructs RewriteRule to escape non-alphanumeric
characters before applying the transformation.

RewriteRule ^a/(.+)$ index.php?data=$1 [L,B]

http://httpd.apache.org/docs/2.2/rewrite/flags.html#flag_b

Plotly Annotation Text: encoding the Hash (#) character in a URL

It's a known bug: plotly/plotly.js#4084

Offending line in plotly.js:

nodeSpec.href = encodeURI(decodeURI(href));
  • decodeURI doesn't decode %23 (decodeURIComponent does).
  • encodeURI doesn't encode # but encodes % (encodeURIComponent does both).

More on that: What is the difference between decodeURIComponent and decodeURI?

Workaround

You can override the built-in encodeURI to revert the encoding of % in %23:

app._inline_scripts.append('''
_encodeURI = encodeURI;
encodeURI = uri => _encodeURI(uri).replace('%2523', '%23');
''')

How can I submit a hash key in an URL parameter?

As Marc B commented, it is necessary to URL encode again. The method would be encodeURI(). However, this method does not encode the # sign. For my specific use case, I have to replace the # sign with %23 after the encoding.

The redirect JS method finally looks like:

    function redir(url) {
url = encodeURI(url);
url = url.replace(/#/g, '%23');
window.location.href = url;
}

Comparing escape(), encodeURI(), and encodeURIComponent()



Related Topics



Leave a reply



Submit