Legacy Confluence Redirect
After migration wiki from on-prem to Attlassian Cloud we’ve got all old links broken. Here is a workaround. 1) Overview A Cloudflare Worker that: Extracts pageId from …/pages/viewpage.action?pageId=… Decodes tiny links /x/<code> → pageId Optionally parses /display/<SPACEKEY>/<TITLE> Looks up SPACEKEY + Title in KV (PAGES) and 301‑redirects to Atlassian Cloud search: https://<new-wiki>.atlassian.net/wiki/search?text=<SPACEKEY> <Title> Enforces an ASN allowlist (e.g., AS12345) on the production host to prevent titles enumeration Uses Workers KV with one record per Confluence page: key = pid:<CONTENTID> → value = {"s":"<SPACEKEY>","t":"<Title>"} Scopes routes only to legacy Confluence paths 2) Prerequisites Cloudflare <your domain> zone access; DNS record for <old-wiki.yourdomain.com> iis Proxied (orange cloud) Windows with PowerShell 5.1+ or 7+ CSV export with columns: CONTENTID,SPACEKEY,TITLE Cloudflare API token with Workers KV Storage: Read & Edit 3) Export mapping from MySQL → CSV -- Use the returned folder from SHOW VARIABLES LIKE 'secure_file_priv'; SELECT 'CONTENTID','SPACEKEY','TITLE' UNION ALL SELECT c.CONTENTID, s.SPACEKEY, c.TITLE FROM CONTENT c JOIN SPACES s ON s.SPACEID = c.SPACEID WHERE c.CONTENTTYPE='PAGE' AND c.PREVVER IS NULL INTO OUTFILE '/var/lib/mysql-files/confluence_pages.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '"' LINES TERMINATED BY '\n'; 4) Cloudflare setup 4.1 Create an API token (UI) Dashboard → My Profile → API Tokens → Create Token → Custom Permissions: Workers KV Storage: Edit and Read. Copy the token to $tok. ...