Why your "free" dynamic QR code stopped working, and how to design one that won't
A QR code is a picture of some text. When that text is a URL, phones open it. That is the whole trick, and it explains most of the problems people run into with QR codes printed on menus, posters and packaging.
A QR code is a picture of some text. When that text is a URL, phones open it. That is the whole trick, and it explains most of the problems people run into with QR codes printed on menus, posters and packaging.
Static and dynamic codes
There are two ways to put a URL into a QR code.
A static code encodes the final destination directly, for example https://example.com/menu.pdf. Nothing sits between the phone and your page. The code works for as long as that page exists, and no service can switch it off. The catch is that you cannot change it: if the menu moves to another address, you reprint.
A dynamic code encodes a short link owned by a service, such as https://short.example/abc123. When someone scans it, the service looks up abc123 and redirects to the current destination. You can change the destination at any time and count the scans, which is why businesses like them.
Where it goes wrong
The redirect is a dependency. Whoever runs short.example decides whether abc123 still resolves. Many QR generators offer dynamic codes during a free trial, then disable the redirect when the trial or the subscription ends. The printed code still scans, but it now lands on an error page or an upsell screen. The owner usually finds out from a customer.
Nothing about this is technical. It is a billing rule placed inside the redirect handler, roughly:
// What many dynamic QR services effectively do
export default {
async fetch(request, env) {
const slug = new URL(request.url).pathname.slice(1);
const code = await env.DB.prepare("SELECT * FROM codes WHERE slug = ?").bind(slug).first();
if (!code) return new Response("Not found", { status: 404 });
if (!code.subscription_active) return Response.redirect("https://service.example/upgrade", 302);
return Response.redirect(code.destination, 302);
},
};
A redirect that ignores billing
If you build a dynamic QR service, the fix is a design decision: keep billing out of the redirect path. Billing can decide who may edit a code or see new statistics. It should not decide whether an existing code resolves.
// Billing never appears in the redirect path
export default {
async fetch(request, env, ctx) {
const slug = new URL(request.url).pathname.slice(1).toLowerCase();
const code = await env.DB.prepare("SELECT destination FROM codes WHERE slug = ?").bind(slug).first();
if (!code) return new Response("Not found", { status: 404 });
ctx.waitUntil(env.DB.prepare("INSERT INTO scans (slug, at) VALUES (?, ?)").bind(slug, Date.now()).run());
return Response.redirect(code.destination, 302);
},
};
Two smaller choices help printed codes too:
-
Make slugs case-insensitive and avoid look-alike characters. If the short link is printed next to the code, people will type it. An alphabet without
l,i,o,0and1removes most typing errors. - Use 302, not 301. Browsers cache 301 redirects, so a destination change may not reach people who already scanned the code.
Choosing a code for print
If the destination will never change, use a static code: it has no dependency at all. If it may change after printing, use a dynamic code from a service whose terms say what happens to the redirect when you stop paying, and read that clause before you print 5,000 flyers.
We built QRLifetime around that rule, and around a pricing choice. Paying a subscription for the whole life of a menu, a package or a sign, just to keep one QR code working, never made sense to us. An editable code is one row in a database and a redirect on a server. So with QRLifetime you can pay once for an editable code, and that's it: no renewal, no plan to keep alive. Static codes stay free and are generated in the browser, and teams who prefer a subscription for many codes keep their codes redirecting after they cancel.
Whatever tool you use, the question to ask is the same: who controls the redirect, and what happens to it when the bill stops?
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.