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
Href Image Link Download on Click
Generate an HTML Response in a Java Servlet
How to Keep Origin in Center of Image in Scale Animation
Can an Option in a Select Tag Carry Multiple Values
Changing Image on Hover With Css/Html
Input Type="Submit" VS Button Tag Are They Interchangeable
Why Is Form Enctype=Multipart/Form-Data Required When Uploading a File
What's the Difference If I Put CSS File Inside ≪Head≫ or ≪Body≫
What Does "For" Attribute Do in HTML ≪Label≫ Tag
Are You Allowed to Nest a Link Inside of a Link
Are Custom Elements Valid Html5
Height of an HTML Select Box (Dropdown)
How to Disable the Resizable Property of a Textarea
How to Use Colspan and Rowspan in HTML Tables
How to Add an HTML Link in the Body of a Mailto Link
Is There a CSS Selector For the First Direct Child Only