On this page

A WordPress site answers far more addresses than its redirect plugin knows about: ?p= links, attachment pages, feeds, archives, paged lists and WordPress’s own guesses. None is in the export. To keep them working on Astro, list every address the old site answers, build one 301 redirect map from that list, and request every old address after the move.

This comes from one migration in November 2026: a 110-page business site moving from WordPress to Astro, with EmDash as the CMS. The method works with any Astro set-up; the one EmDash section is marked. Where a claim comes from our move, we say so.

What was checked, and on what. The Astro behaviour is from Astro’s docs, read on 23 November 2026, and we ran the middleware sketch below on Astro 7.4.13. The WordPress and Yoast behaviour is from their docs, read the same day. Our own redirect checks ran on a private test copy of the new site, on EmDash 1.5.0, and again after it moved to EmDash 1.6.0 on 25 November 2026. The site has not switched over yet.

What a 301 redirect map is, and why WordPress’s is bigger than you think

A 301 redirect map is a table: every old address, its new address, and the code (301, moved for good). Most people start from the redirect plugin’s export. That holds only the rules someone typed in. In our move the Redirection plugin had 161 rules, all 301, 158 enabled, 2 of them regular expressions. WordPress answered many more addresses than that, with no rule anywhere.

  • Short links. Every post and page has a numeric ID, and /?p=<id> sends visitors to it with a 301. Our first comparison found 105 ?p= page IDs with no redirect on the new site.
  • Guessed redirects. WordPress answers a mistyped or relative address with a 301 to its best guess. A relative contact/ link on /blog/<post>/ asks for /blog/<post>/contact/, and WordPress quietly sends the visitor to /contact/. A plain Astro site answers 404.
  • Old slugs. Rename a post and WordPress keeps answering at the old slug. In our move, links inside the content pointed at 13 targets that answered only through the old site’s 301s: 11 drafts and 2 old addresses.
  • Archives and paged lists. /category/<x>/, /tag/<x>/, /author/<x>/, date archives, /page/2/, /blog/page/2/.
  • Feeds. /feed/, /comments/feed/, /<post>/feed/ and category feeds. Each item’s <guid> is https://<your-domain>/?p=<id>. Keep those guids in the new feed, or feed readers show every post as new.
  • Old sitemap names. Yoast serves /sitemap_index.xml, /post-sitemap.xml, /page-sitemap.xml and /<type>-sitemap.xml.
  • Both forms of every address. WordPress answers with and without the closing slash and redirects one to the other.

What “redirect attachment pages” means once you leave WordPress

Every uploaded file is an attachment, reachable at /?attachment_id=<id> and often at /<attachment-slug>/. “Redirect attachment pages” means sending those addresses to the file instead of a thin page around it.

What your site does today depends on its history and its plugins:

  • Since WordPress 6.4, attachment pages are off on new installs. The wp_attachment_pages_enabled option is 0 there, and WordPress redirects attachment pages to the file. Sites upgraded from older versions got 1, so their attachment pages still show.
  • Yoast SEO has its own switch, Media pages. With it off, Yoast redirects attachment addresses to the file.
  • Two WordPress bug reports, both open when we read them in November 2026, say the redirect misses one form or the other: one says the slug form answers 200 while ?attachment_id= redirects, the other the reverse.

So request both forms for a few attachments on your live site and record what each does: a page, a redirect to the file, or a 404. Then map every one. Ours had 499 attachment addresses with no redirect at first: 391 answered 404 on the new site and 108 answered the home page.

Where to find every old WordPress address

No single file has the full list. Put these together:

  • The sitemaps. Ours had 110 public addresses. None of the groups above was in them.
  • The redirect plugin’s export (Redirection gives JSON or CSV).
  • The WordPress export file (Tools, Export, All content). It holds every post, page and attachment with its ID, so it gives you the ?p= and ?attachment_id= lists. Old slugs are in post meta named _wp_old_slug.
  • Search Console. Export the Pages report and the Top linked pages.
  • Server logs, if your host keeps them.
  • The links inside your content. Collect every internal link target from post bodies, custom fields and menus, then request each one on the live site. In ours, 243 links in body text were full addresses on the old domain; we made 372 links site-relative in all, to 57 targets.
  • Every relative link, listed separately: WordPress rescues these by guessing.

Build one 301 redirect map: one hop, no chains

Put every old address in one table, with the new address and the code. Then clean it:

  • One hop only. If A goes to B and B goes to C, point A at C. Ours had 29 chains, flattened to one hop each, with no loops.
  • Drop rules whose source is now a real page. In Astro’s redirects the page file wins; other systems check redirects first and hide the page.
  • Drop disabled rules, duplicates and rules to pages you are not rebuilding. After those drops we loaded 156 rules.
  • Strip your own domain from targets, so each is a path. Keep the site’s closing-slash style (below).
  • Regular expressions. Rewrite each as a pattern, or as a list of addresses.
  • Query strings. Ad links carry click IDs after ?. If a redirect drops the query string, the click ID is lost; change the ads’ final URLs to the new pages before the switch.
  • IDs to paths. Build the ?p= and ?attachment_id= maps from the export: ID, then new address. Send an attachment to its file or to its post.

Astro redirects: config, middleware or the host

  • The host’s redirect rules. Many hosts read a redirect file, usually before your site runs. Many match the path only, and some limit the number of rules. Test a rule from the end of your list.
  • Astro’s redirects setting. The redirects option in astro.config maps old paths to new ones, and patterns such as "/blog/[...slug]": "/articles/[...slug]" work when both sides have the same parameters. With no adapter, a static build writes small HTML pages with a meta refresh: a browser redirect with no status code. With a supported adapter, Astro writes the rules into the host’s configuration, as 301s for GET requests and 308s for other methods.
  • Middleware. Code that runs before a page. It can read the query string and answer with a 301. But for prerendered pages Astro runs it once, at build time, when there is no query string to read. It runs on each request only for routes rendered on demand.

Astro redirect middleware for ?p= and other query strings

A request for /?p=123 asks for the home page. So the home route must be rendered on demand for middleware to see p. If your home page is prerendered, put these rules at the host instead, if it can match query strings. A sketch, with the map built from your export file:

// src/middleware.ts
import { defineMiddleware } from "astro:middleware";
import idMap from "./redirects/wp-ids.json"; // { "123": "/blog/some-post/" }

const targets: Record<string, string> = idMap;

export const onRequest = defineMiddleware((context, next) => {
  const { pathname, searchParams } = context.url;
  if (pathname === "/") {
    const id = searchParams.get("p") ?? searchParams.get("attachment_id");
    const target = id ? targets[id] : undefined;
    if (target) return context.redirect(target, 301);
  }
  return next();
});

Pass 301 yourself: context.redirect sends a 302 if you give no status.

We ran this sketch on 23 November 2026, on a scratch Astro 7.4.13 project with the Node adapter and output: "server". /?p=123 and /?attachment_id=123 answered 301 to /blog/some-post/, also with another parameter beside them. /?p=999, / and /?utm_source=x answered 200. With the home page prerendered, /?p=123 answered 200: the middleware never saw the query. The targets line is there for TypeScript’s strict check. The sketch was written for this guide; it is not the code our site runs.

Astro trailing slash redirect: keep WordPress’s slash style

WordPress addresses usually end with /. Keep that in every target, so visitors arrive in one hop, not two.

Astro’s trailingSlash setting is 'ignore' by default. Set to 'always' or 'never', it redirects the wrong form with a 301, but in production only for routes rendered on demand. For prerendered pages the host decides, and Astro’s docs say its redirects cannot fix that. Pair 'always' with build.format: 'directory', and test a slashless request on your host.

On EmDash 1.5.0 and 1.6.0 (skip if you are not using it)

We read these limits in EmDash 1.5.0’s source. The change in 1.6.0 is from its release notes; we did not read the source again.

  • EmDash has a redirect table built in. It checks redirects before pages, so a rule whose source is now a page hides that page.
  • It matches paths only, case-sensitively, and drops the query string on redirect.
  • Patterns use [param] for one segment and [...rest] for the rest. There are no regular expressions.
  • Targets must be paths on your own site.
  • Before EmDash 1.6.0, addresses ending in a file type, such as /sitemap_index.xml or /old/report.pdf, are never redirected: the rule is saved but not applied. EmDash 1.6.0’s release notes, and the change behind them, say an exact rule for such an address now works, and pattern rules still do not apply to file addresses. We have not tried this ourselves. We served the old sitemap names from middleware, on 1.5.0.
  • ?p= and attachment addresses need middleware with an ID map, as above.

To load a WordPress list, see how to import your WordPress redirects into EmDash. The import there is in SEO & Schema Markup. Disclosure: we make this plugin. Before 0.3.1 it skipped rules whose target was a full address on the same site: 132 of our 161. You can also add rules one at a time under Redirects in EmDash’s admin. For the rest of the move, see moving a whole WordPress site to EmDash.

Check every redirect after the migration

Run it before you switch the domain, and again after.

  • Request every old address, with and without the slash, and require one hop to a 200. A 301 to a 404, or two 301s in a row, is a failure.
  • Check pages too. Every page you kept should answer 200, not a redirect.
  • For doubtful links, ask the live old site, not a saved copy, and record its hop.
  • Compare old and new, address by address: status, final address, title, canonical, visible text. Run the same checks on the old pages, so their faults are not counted as yours.

What our own checks found. An early redirect check made 323 requests with 0 failures, but tested only our list. The first page-by-page comparison, over 109 addresses, found what it missed: ?p= and attachment addresses, relative links the old site had rescued by guessing, and one paged list address.

We added the missing redirects to the private test copy. On 23 November 2026, on EmDash 1.5.0, the redirect check there made 1,327 requests with 0 failures: the 156 rules with and without the slash, pattern samples, the old sitemap names, 109 ?p= addresses, paged blog addresses and attachment addresses. Of the attachment addresses, 222 now go to the file, 416 to the entry they belonged to, and 252 answer as before because neither exists. A second comparison there showed every redirect fault from the first gone. The one address still open then, /page/2/ at the site root, now redirects to the home page, which is what the old site showed there. On 25 November 2026, after the test copy moved to EmDash 1.6.0, the redirect check ran again with 0 failures. The site has not switched over yet, so there are no live or search results. Checking your map proves your map, not your site.

Checklist

  1. Export the redirect rules and the WordPress export file.
  2. List ?p=, attachment, archive, paged, feed and old sitemap addresses, plus Search Console, logs and internal link targets.
  3. On the live site, request relative links and both attachment forms; record each hop.
  4. Build one map: one hop, no rules over real pages, your slash style, paths.
  5. Put each rule where it can run: host, redirects, or middleware on an on-demand route.
  6. Change ad final URLs to the new pages.
  7. Request every old address, with and without the slash: one hop to a 200.
  8. Compare every address with the old site, before and after the switch.

Changes to this guide. 25 November 2026: first version.

Stuck on a step? Email hello@moorage.dev.

What should we make next?

Tell us the job you would like a plugin to do. We read every answer and use your email only to reply to it; release emails come only if you tick the box.