IIS replacing multiple forward slashes in a URLRSS

2 replies

Last post Feb 07, 2020 12:30 PM by Lewis-H

  • IIS replacing multiple forward slashes in a URL

    Feb 05, 2020 02:36 PM|PrachiS798|LINK

    We are using IIS version 10. An application uses multiple forward slashes in it's relative URI for the file location. Example:


    The IIS combines multiple forward slashes into a single forward slash when matching URI to file location.

    However, this breaks the address of the file location in the application.

    Is there a way to stop IIS from combining multiple forward slashes into a single one?

    Many thanks

  • Re: IIS replacing multiple forward slashes in a URL

    Feb 06, 2020 06:30 AM|Jalpa Panchal|LINK

    Hi Prachi,

    You could try to use the IIS URL rewrite rule encodes the URL by using it. Could you please share which kind of application you are using?

    For that first, you need to install the URL rewrite extension iis. you could install it by using the web platform installer or by using below link:


    below is the example about how you could encode url:

     <rule name="rule1" stopProcessing="true">
                        <match url="(.*)" />
                        <action type="Redirect" url="{UrlEncode:{R:1}}" />

    you could also refer this below link:




    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue.
    If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
  • Re: IIS replacing multiple forward slashes in a URL

    Feb 07, 2020 12:30 PM|Lewis-H|LINK

    The issues I was having using the IIS URL Rewrites was due to the way IIS caches the redirects. When I disabled caching completely, as WouterH suggested, it worked. However, I'm not comfortable disabling caching in this way as it could introduce performance issues.

    My fix was to use a code behind redirect in the Global.asax.cs file:

    protected void Application_BeginRequest(object sender, EventArgs e)
        string requestUrl = Request.ServerVariables["REQUEST_URI"];
        string rewriteUrl = Request.ServerVariables["UNENCODED_URL"];
        if (rewriteUrl.Contains("//") && !requestUrl.Contains("//"))

    I would have liked to use IIS URL Rewrite to get this working, unfortunately I didn't have the time to continue down that line.

    Interestingly, the below method did work, however, the HTTP_X_REWRITE_URL is added by the Helicon ISAPI Rewrite which I'm running locally, but is not available on our production server.

        <rule name="Remove multiple slashes" stopProcessing="true">
          <match url=".*" />
          <action type="Redirect" url="{REQUEST_URI}" />
            <add input="{HTTP_X_REWRITE_URL}" pattern="([^/]*)/{2,}([^/]*)" />

    I have resorted to using a code behind redirect to get it working.