Removing &PageSpeed=noscript from the end of URL IIS Rewrite

Viewed 46

I am trying to remove the last part of the URL with IIS Rewrite, but somewhere I do the things wrong. Example URL: https://example.com/BGLog/pages/register/?ReturnUrl=/blog/arebemagare/site/posts/?bid=37780&PageSpeed=noscript I need to remove &PageSpeed=noscript I wroted rule, but it strips also ?ReturnUrl=/blog/arebemagare/site/posts/?bid=3778 :

 <rule name="Remove paging parameters" stopProcessing="true">
<match url="(.*)?$" />
<conditions trackAllCaptures="true">
                    <add input="{QUERY_STRING}" pattern="(.*)(.*)&amp;PageSpeed=noscript(.*)" />
</conditions>
<action type="Redirect" url="{R:1}" appendQueryString="false" redirectType="Temporary" />

Any suggestion? Thanks!

3 Answers

I think I've achieved it, but with two rules:

   <rule name="Remove &PageSpeed" stopProcessing="true">
    <match url="(.*)" />
    <conditions logicalGrouping="MatchAny" trackAllCaptures="true">
                        <add input="{QUERY_STRING}" pattern="(.*)(&amp;PageSpeed=noscript)" />
    </conditions>
    <action type="Redirect" url="{R:1}?{C:1}" appendQueryString="false" redirectType="Found" />
</rule>
<rule name="Remove ?PageSpeed" enabled="true" stopProcessing="true">
  <match url="(.*)?$" />
  <conditions>
                        <add input="{QUERY_STRING}" pattern="(.*)(PageSpeed=.+)(.*)" />
  </conditions>
  <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="false" redirectType="Permanent" />
</rule>

Please try the following rule:

        <rewrite>
            <rules>
                <rule name="test" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{QUERY_STRING}" pattern="(.*)&amp;(PageSpeed=noscript)" />
                    </conditions>
                    <action type="Redirect" url="{R:1}?{C:1}" appendQueryString="false" />
                </rule>
            </rules>
        </rewrite>

The result of my test is working, hope this works for you too.

Related