haroon latif
haroon latif

Reputation: 53

URL Redirect web.config

I have the following URL

https://www.abcsite.com/?data=w35VTqIaVXWfi4GmESj8EGCG1cdF2aT%2BUF3D?utm_source=external%20system&utm_campaign=external%20system&utm_medium=EX.com&utm_content=MMB

which has extra ? at the end. which I Would like to remove and replace with "&"

I am using following rule but it is not working. can you review this and tell me what I am doing wrong.

 <rewrite>
  <rules>
    <rule name="fixdata" stopProcessing="true">
      <match url="\?(.*)\?(.*)$"  ignoreCase="false" />
      <action type="Redirect" redirectType="Permanent" url="http://www.example.com/{R:1}&{R:2}" />
    </rule>
  </rules>
</rewrite>  

Thanks.

Upvotes: 0

Views: 495

Answers (1)

Victor Leontyev
Victor Leontyev

Reputation: 8736

You rule should be like this:

<rule name="fixdata" stopProcessing="true">
    <match url=".*" />
    <conditions>
        <add input="{QUERY_STRING}" pattern="(.*)\?utm_source(.*)$" />
    </conditions>
    <action type="Redirect" url="{R:0}?{C:1}&amp;utm_source{C:2}" appendQueryString="False" />
</rule>

Your rule didnt work, because <match url= contains path without query string. You need to create additional condition to match query string with your regexp pattern

Upvotes: 1

Related Questions