How to write a regex to remove the last parameter from a url

I am trying to create a URL rewrite rule for IIS to return the URL before a specific parameter.

Edited: I should have indicated that authProvider is always the last parameter.

Example:

http://localhost/WebAccess/Default.ashx?accessionNumber=009&authProvider=Bypass

I want to trim & authProvider = crawl from end of URL

I tried:

.*(?=&authProvider)

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Test" enabled="true">
                    <match url="(.*)&amp;authProvider.+" />
                    <action type="Rewrite" url="{R:0}" logRewrittenUrl="true" />
                </rule>
            </rules>
        </rewrite>

    </system.webServer>
</configuration>

enter image description here

+3
source share
1 answer

The example you showed will match what you want, but don't change the URL. The result of your match should have the agreed line that you want as the result.

, , , , (?= ), , . , , , , , :

(.*)&authProvider.+

$1

:

http://localhost/WebAccess/Default.ashx?accessionNumber=009

, $auth, 1 ($1).

, {R: 1}, {R: 1}, Rewrite {R: 1}. . .

+1

All Articles