The rule works, unless utm_ is in the URL, but my other parameters do work. Since this didn’t make sense, I placed Cloudflare in Development mode, and then utm_ was properly being remove from the URL. However, once I enable Cloudflare again, only utm_ is not removed, amp= and m= is always removed in all cases.
Ironically enough, it looks like there was a recent issue with utm_ and I can’t help but wonder if the two issues are tied together?
Under APO, your origin will never see any query string with utm_ parameters, or any other marketing-related parameters in this list. APO removes those parameters (when no other, dynamic query string element is present) to make these pages cacheable.
No. The issue you linked to was resolved at the time. For a while, a bug was hindering the expected behavior (described above), but that was fixed back then.
The way APO works is by removing these marketing parameters between the edge (Cloudflare network) and the origin. In your browser, the utm_ will still show in the address bar, but since they have been removed from the path requested to the origin, the redirection you’ve set at the origin with the .htaccess directives will not work for these marketing parameters.
In the browser:
Request for https://example.com/post?utm_source=x
Sent to the origin: https://example.com/post (but you still see the query in the browser’s address bar.)
That URL does not trigger your .htaccess rule, as it does not contain the matching query string. Therefore, there’s no redirect.
Compare to:
Request for https://example.com/post?amp=x
Sent to the origin: https://example.com/post?amp=x
That URL triggers your .htaccess rule, and you get:
301 for https://example.com/ (this URL change will show in the address bar.)
So Cloudflare is intervening here. I wonder how this affects search rankings. I still have URLs in Google Search Console that show the ?utm_source in the URL. I was hoping to 301 those.
Redirecting URLs with utm_ would affect your Analytics software, or someone else’s, like an advertiser’s, or that of a third party linking to your website, and it’s not the best way to set the canonical URL for these links. A redirection would prevent the analytics software JavaScript to be loaded. The way APO handles it is better, as it occurs after JS has run, and only between Cloudflare and edge, not affecting what the browser sees.
I should be set then, I have the proper rel=canonical set on my site. I sure would like to see Search Console update those URLs to the proper rel=canonical though.