IIS 7 and Above
URL Rewrite Module
How to Handle "#" in URL in IIS
Last post Sep 25, 2020 09:09 AM by Brucz
Sep 02, 2020 02:32 AM|Enterfrize|LINK
Running Windows Server 2012 R2 IIS IIS 8.5
The file we need the URL to point to is:
It comes back as a bad link. The only way this and similar URLs can be parsed to work is:
The actual file is stored as "AssassinsCreed_Dx9_#0041.jpg" in the directory. What am I doing wrong? Do I need a special rewrite rule, etc.? All guidance valued.
Sep 02, 2020 03:06 PM|Enterfrize|LINK
This may be a hint, but I don't know how to use it:
PRESERVING ORIGINAL URL
The URL Rewrite Module preserves the original requested URL path in the following server variables:
HTTP_X_ORIGINAL_URL – this server variable contains the original URL in decoded format; UNENCODED_URL – this server variable contains the original URL exactly as it was requested by a Web client, with all original encoding preserved.
IIS seems to be doing an on-the-fly encoding or conversion of the hash (#) to an ascii code in the URLs. How do I stop that?
Sep 03, 2020 02:05 AM|lextm|LINK
"#" is a keyword for URL fragments, so "we need the URL to point to is" is an invalid requirement. You cannot find basic internet standards,
IIS performs the escaped conversion for you, so you either accept that, or go back to rename your files to not use any "#" in names.
Sep 03, 2020 10:09 AM|Brucz|LINK
For your needs, it is currently impossible to achieve, because # in the url has other functions, please refer to
this explanation for details.
If you don’t want to change the image name, you can only escape the # when entering the url. Like this:
Sep 03, 2020 07:12 PM|Enterfrize|LINK
I think I know what happened.
The site was recently upgraded to a different CMS. I looked at the URLs of some of the broken image articles. Here is an example.
In a broken image link, it points to:
and when it gets converted to https:// by IIS rewrite, it becomes:
So the rewrite rule that converts HTTP:// to HTTPS:// needs to preserve the %23 encoding that is in the URLs.
Is that difficult to do?
Sep 25, 2020 09:09 AM|Brucz|LINK
When http redirect to https, it can preserve the %23.
Changing the http security protocol only affects the https server variables, and does not affect the URL.