Search code examples
url-rewrite-moduleiis-10

IIS URL Rewrite removing part of path


because a Software provider changed the URL of a Programm hosted in my IIS, I now have many broken links. The URL used to be

https://example.com/#/subdomain/and/here/some_more

now it is

 https://example.com/#/and/here/some_more

They just took away the first part of the path (subdomain)

I thought I could fix my links with an URL Rewrite rule. I tried this:

    <rewrite>
        <rules>                
            <rule name="example" stopProcessing="true">
                <match url="(https:\/\/example\.com\/#)(\/subdomain)(\/.*)" ignoreCase="true"/>
                <action type="Redirect" url="https://example.com/#{R:3}" appendQueryString="false" />
            </rule>
        </rules>
    </rewrite>

This actually matches in the "Test Pattern" but it doesn't redirect. enter image description here

I also tried using :

url="{R:1}{R:3}

but still no redirect is happening. I tried with different browsers with no success.

Thanks for the help


Solution

  • The number sign (#) delimits the URI from the fragment identifier. The client should never send this character uncoded. Instead, the client should only send the URI to the server (everything before #). So your client application (web browser) does not send anything after #, which we can see in the URL logged on the server. So what you need to do is to encode this character.

    https://learn.microsoft.com/en-us/iis/extensions/url-rewrite-module/url-rewrite-module-configuration-reference