read about this site and my work or check what I'm doing now

#programming #medium #nudged

How I Fixed Medium’s Query Parameter Issue

Earlier I created an "About page" on Medium  with several inline links back to my notes on Blot.im. But I noticed that all the links started rendering as .md files on my Blot site, even the homepage—which had never happened before. At first, I wasn’t sure if this was a quirk of Medium’s outbound link handling or something on Blot’s end. That’s when I noticed that Medium automatically adds query parameters like ?source=user_about to every outbound link.

I asked around for solutions. Someone suggested adding extra parameters, like ?nope, to the end of the URLs, hoping that Medium’s ?source would stack neatly behind it, but that didn’t work. Medium simply converted the second ? to &—still triggering the source view. I also tried appending anchors, like #top, to bypass the issue, but Medium just tacked those on without changing the behaviour. I even experimented with URL encoding, creating redirects, and messing with permalinks (which I knew was futile). Nothing stuck.

Eventually, I realised the easiest solution was to strip the query parameters entirely using Cloudflare Workers. Here’s the setup I used to finally solve the issue.

Creating a Subdomain on Cloudflare

  1. Go to the DNS Settings in the Cloudflare dashboard.
  2. Click Add Record.
  3. Create a CNAME Record:
    • Type: CNAME
    • Namemedium
    • Targetdomain.tld (or your apex domain)
    • Proxy Status: Enabled (orange cloud)
  4. Save the DNS Record.

This creates the medium.domain.tld subdomain and routes traffic through Cloudflare. With the Worker applied to this subdomain, requests like: https://medium.domain.tld/link?source=user_about----------------------t0530a9dc77a--------------- are properly intercepted by the Worker, ensuring query parameters are stripped while keeping the path intact.

Using Cloudflare Workers to Remove Query Parameters

  1. Create a Cloudflare Worker:
    • Go to Workers & Pages in the Cloudflare dashboard.
    • Click Create Application > Workers > Quick Edit to access the code editor.
  2. Use the Following Worker Code:
async function handleRequest(request) {   const url = new URL(request.url);   const newUrl = `https://domain.tld${url.pathname}`; // Strip query parameters   return Response.redirect(newUrl, 301); }  addEventListener("fetch", event => {   event.respondWith(handleRequest(event.request)); });
  1. Set Up the Route:
    • Go to Settings > Domains & Routes within the Worker’s configuration.
    • Click + Add and enter the route: medium.domain.tld/* Remember to change domain.tld to your own domain!
    • Choose Fail open (proceed) to ensure requests still go through if the Worker fails.
  2. Clear Your Browser Cache:
    • If the query parameters still appear after setting this up, clear your browser cache or test the link in an incognito window. Cloudflare might be working correctly, but your browser may serve cached results.

Now, when Medium adds its ?source=user_about query parameter to my links, Cloudflare strips it out, ensuring that the correct pages render without triggering the source view. This way, the path remains intact and the query parameters are discarded seamlessly.