0

I have searched through many S.O. questions and answers, but haven't seen a good solution for this. I have already created and well-established SEO URLs in my web.config file. I was using a rewriteMap to basically turn my product pages into any URL that I needed.

Here is what I have to do this:

<rule name="Redirect Rule" enabled="true" stopProcessing="true">
    <match url=".*" />
    <conditions>
        <add input="{RedirectMapName:{REQUEST_URI}}" pattern="(.+)" />
    </conditions>
    <action type="Redirect" url="{C:1}" appendQueryString="false" redirectType="Permanent" />
</rule>
<rule name="Rewrite Rule" stopProcessing="true">
    <match url=".*" />
    <conditions>
        <add input="{RewriteMapName:{REQUEST_URI}}" pattern="(.+)" />
    </conditions>
    <action type="Rewrite" url="{C:1}" />
</rule>

What is being requested now is to add in Google Analytics parameters in order to track campaigns. If I simply add in the parameters, it will of course, give me a 404 error. I am now trying to get these SEO URLs to pick up these parameters, but getting quite frustrated.

If I remove the query string, Google Analytics will not pick it up since it is a client side script. Something like this might be close, but I am not pointing to any specific page. URL Rewrite with Query String

This is how I remove the querystring:

<rule name="Subject redirect with query" stopProcessing="true">
         <match url="^(.*)" />
         <conditions trackAllCaptures="true">
            <add input="{QUERY_STRING}" pattern="^utm_source=([^=&amp;]+)&amp;utm_medium=([^=&amp;]+)&amp;utm_campaign=([^=&amp;]+)&amp;?(.*)$" />
         </conditions>
         <action type="Redirect" url="{R:1}" appendQueryString="false" redirectType="Permanent" />
</rule>

Summed up, how do I turn this:

https://www.example.com/fancy-url

to this

https://www.example.com/fancy-url?utm_source=Targeted_Email&utm_medium=email&utm_campaign=campaigntag
illinoistim
  • 456
  • 10
  • 27
  • Can you provide me this solution in reverse order? My server blocks the url having utm_mediam and utm_source parameters – Tasaddaq Rana Sep 21 '21 at 08:17

1 Answers1

0

After much frustration, I was able to figure this out. The query string was okay, but one of the settings was preventing the rest of the rules to be processed. After the rule name, I had stop processing set to true. When I looked at it in IIS, the setting is much more descriptive. It says "Stop processing of subsequent rules". Once I removed that and moved this above my other rules, worked perfectly.

<rule name="Google Query string">
      <match url="(.*)$" />
      <conditions>
        <add input="{QUERY_STRING}" pattern="utm_source=([^=&amp;]+)&amp;utm_medium=([^=&amp;]+)&amp;utm_campaign=([^=&amp;]+)&amp;?(.*)$" />
      </conditions>
      <action type="Rewrite" url="{R:0}" appendQueryString="false" />
    </rule>
illinoistim
  • 456
  • 10
  • 27