Skip to content

Instantly share code, notes, and snippets.

@seemly
Created September 4, 2025 13:41
Show Gist options
  • Select an option

  • Save seemly/08f9b1cfcc94a1188833b84654f6c1f4 to your computer and use it in GitHub Desktop.

Select an option

Save seemly/08f9b1cfcc94a1188833b84654f6c1f4 to your computer and use it in GitHub Desktop.
WP Engine - Bulk Export Rewrite Rules
/*================
In the absence of support to Bulk Export all rewrite rules from WP Engine, I wrote the following snippet.
1.) Navigate to the Rewrite Rules in the Web Rules section of your WP Engine dashboard.
2.) Copy and paste the below code into your web dev console.
3.) Save the CSV to your machine.
================*/
(() => {
const rows = document.querySelectorAll("tr.MuiTableRow-root");
const data = [];
rows.forEach(row => {
const cells = row.querySelectorAll("td");
if (cells.length < 7) return;
const grab = el => {
if (!el) return "";
const span = el.querySelector("span");
return span?.getAttribute("aria-label")?.trim() || span?.innerText?.trim() || el.innerText.trim() || "";
};
const type = cells[1]?.innerText.trim() || "";
const source = grab(cells[2]);
const target = grab(cells[3]);
const behaviour = cells[4]?.innerText.trim() || "";
const comment = cells[5]?.innerText.trim() || "";
const andCond = cells[6]?.innerText.trim() || "";
if (!source && !target) return;
data.push([type, source, target, behaviour, comment, andCond]);
});
const header = ["Type","Source","Target","Behaviour","Comment","AndCondition"];
const csv = [header, ...data]
.map(r => r.map(v => `"${v.replace(/"/g, '""')}"`).join(","))
.join("\n");
const blob = new Blob([csv], {type: "text/csv"});
const url = URL.createObjectURL(blob);
const a = Object.assign(document.createElement("a"), { href: url, download: "rewrite-rules.csv" });
document.body.appendChild(a);
a.click();
URL.revokeObjectURL(url);
a.remove();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment