BareProxy Redirects From a File Plugin: Thousands of Old URLs Moved Without Config Lines
Status: planned, number 4 of 21 in BareProxy’s build order. The plugins are built easiest first, and this one is about half a day of coding: one file read into a table, reloaded on a timer. It comes after the Header and rewrite rules plugin. This post describes what it will do, and it will be updated as it is built.
Every site migration leaves a trail of old URLs: a CMS that put dates in paths, a blog that moved from /p/123 to /posts/title, a shop that renamed every category. Each old URL that still has links pointing at it needs a permanent redirect, or the links break and the search ranking that came with them is lost. A migration can easily mean ten thousand redirects.
BareProxy’s core can redirect, one rule per line in the config. That is right for a handful. For ten thousand it isn’t: the config becomes unreadable, and every request would be checked against a long list of rules.
What It Will Do
- Read a plain file. One redirect per line, old path and new URL, in a folder the plugin’s config names. The kind of file a migration script or a spreadsheet export produces.
- Look up, not scan. The file is loaded into a table, so a request costs one lookup whether there are ten redirects or a hundred thousand.
- Keep the query. The query string goes along to the new address, unless the line says otherwise.
- Reload on change. A changed file is picked up on its own, checked first, and a file with a broken line is refused while the old one keeps working. That’s BareProxy’s rule for configs, applied to the redirect list.
- Count hits. Each redirect’s use is counted, so after a few months it’s clear which old URLs still matter and which can go.
A config will look something like this:
plugin moved /etc/bareproxy/plugins/redirects.wasm
config /etc/bareproxy/plugins/moved.json
read /etc/bareproxy/redirects
site example.com
use moved
route /* -> files /var/www/example/public
Every redirected request carries a note in its record with the line of the file that matched, so why on any old URL says exactly where it went and why.
The whole program is on the plugins page.