How to Handle "#" in URL in IISRSS

5 replies

Last post Sep 25, 2020 09:09 AM by Brucz

  • How to Handle "#" in URL in IIS

    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:

    https://www.mtbs3d.com/gallery/albums/assassinscreed/AssassinsCreed_Dx9_#0041.jpg

    It comes back as a bad link.  The only way this and similar URLs can be parsed to work is:

    https://www.mtbs3d.com/gallery/albums/assassinscreed/AssassinsCreed_Dx9_%230041.jpg

    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.

  • Re: How to Handle "#" in URL in IIS

    Sep 02, 2020 03:06 PM|Enterfrize|LINK

    This may be a hint, but I don't know how to use it:

    https://stackoverflow.com/questions/21413393/how-to-stop-iis-from-decoding-url

    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?

  • Re: How to Handle "#" in URL in IIS

    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, https://en.wikipedia.org/wiki/URL#Syntax

    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.

    Lex Li
    Affordable IIS Consulting Services at https://support.lextudio.com/services/consulting.html
    ---------------------------
    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: How to Handle "#" in URL in IIS

    Sep 03, 2020 10:09 AM|Brucz|LINK

    Hi Enterfrize,

    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:

    https://www.mtbs3d.com/gallery/albums/assassinscreed/AssassinsCreed_Dx9_%230041.jpg

    Best regards,

    Brucz

  • Re: How to Handle "#" in URL in IIS

    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.

    https://www.mtbs3d.com/articles/game-reviews/2736-star-trek-legacy-s-3d-review.html

    In a broken image link, it points to:

    http://www.mtbs3d.com/gallery/albums/userpics/10002/izlegacy_%230016.jpg

    and when it gets converted to https:// by IIS rewrite, it becomes:

    https://www.mtbs3d.com/gallery/albums/userpics/10002/izlegacy_#0016.jpg

    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?

  • Re: How to Handle "#" in URL in IIS

    Sep 25, 2020 09:09 AM|Brucz|LINK

    Hi Enterfrize

    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.