Back to blog
7 min read Export Guides

Build a 301 Redirect Map from Before and After URL Exports

When you change the permalink structure, rename slugs or move posts to a new section, every old URL that Google, newsletters and other sites link to turns into a 404. A redirect map fixes that: a list of old URL → new URL pairs that a redirect plugin or the server turns into 301 redirects. Two exports made with Import Export by RockStarLab, one before the change and one after, matched by post ID, give you the map. In our test, switching a blog of 74 posts from /2026/10/14/post-name/ to /blog/post-name/ broke all 74 old URLs, and the map from this guide redirected every one of them.

Free: export of posts, pages and products with ID and Permalink to CSV, XLSX, ODS, JSON or XML. PRO: transformations of values during export, such as cutting the domain off the URL.

Short Answer

  1. Before the change, export your posts with the columns ID and Permalink to before.csv.
  2. Change the permalinks, then make the same export again to after.csv.
  3. In a spreadsheet, look up each ID from the first file in the second, keep only the rows where the URL changed and cut the domain off both URLs.
  4. Save the pairs as a CSV in the format of your redirect plugin and import it. Old URLs now answer with a 301 to the new ones.

Why match by ID and not by URL

The post ID is the one thing that stays the same when the slug, date path or category in the URL changes. With ID in both exports, each old URL finds its new URL with one lookup, even when you renamed dozens of slugs at once. An export of all site URLs (see exporting all site URLs) is handy as a checklist, but it has only the URL, so it can’t tell you which new URL belongs to which old one.

The before export has to happen before the change. Once the permalinks are changed, WordPress only knows the new URLs. If you’ve already made the change, restore a backup on a staging copy and export from there.

Step 1: Export the URLs before the change

Go to Import Export → Export, choose Blog Posts and click Next Step. You don’t need filters: drafts and scheduled posts have no public URL yet, and you’ll drop rows that didn’t change later anyway. In step 3, add ID and Permalink; Title and Status make the file easier to read.

Blog Posts export step 3 with the columns ID, Title, Status and Permalink
ID and Permalink are all the redirect map needs; Title and Status help you read the file.

Choose CSV or XLSX in step 4, click Start Export and save the file as before.csv. If pages, products or another post type will change too, make one export per type. Our file had 76 rows:

ID,post_title,post_status,permalink
1863,"How We Source Green Coffee",publish,https://example.com/2026/10/14/how-we-source-green-coffee/
1861,"Five Single-Origin Coffees to Try This Winter",publish,https://example.com/2026/10/13/five-single-origin-coffees-to-try-this-winter/

Step 2: Make the change and export again

Change the permalinks the way you planned: a new structure in Settings → Permalinks, new slugs, or a new parent page. Then run the same export again and save it as after.csv. Use the same columns in the same order, so both files line up.

In our test, the new structure was /blog/%postname%/. Right after saving it, all 74 old URLs returned 404 Not Found: WordPress did not redirect them by itself.

Step 3: Pair old and new URLs in a spreadsheet

Open before.csv in Excel or Google Sheets and add after.csv as a second sheet named After. With ID in column A and Permalink in column D on both sheets, add three columns to the first sheet:

Column Formula Result
E: New URL =XLOOKUP(A2, After!A:A, After!D:D, "") The permalink of the same ID after the change
F: Old path =MID(D2, FIND("/", D2, 9), 999) /2026/10/14/how-we-source-green-coffee/
G: New path =MID(E2, FIND("/", E2, 9), 999) /blog/how-we-source-green-coffee/

The FIND("/", …, 9) part finds the first slash after https://, so the formula cuts off the domain. Older Excel versions without XLOOKUP can use =INDEX(After!D:D, MATCH(A2, After!A:A, 0)). Then filter the sheet to the rows where F is not equal to G. In our file, 74 rows were left: the draft and the scheduled post kept their ?p= address and dropped out.

Use paths and not full URLs as the source: a redirect plugin compares the path of the request, so a full URL with the domain would never match. If you’re also moving to a new domain, keep the full new URL in the target column instead of the path.

Step 4: Import the map into a redirect plugin

The free Redirection plugin imports a CSV without a header with four columns: source path, target, 0 for a plain match (1 would mean a regular expression) and the HTTP code. Copy columns F and G to a new sheet, add the two constant columns and save it as redirects.csv:

/2026/10/14/how-we-source-green-coffee/,/blog/how-we-source-green-coffee/,0,301
/2026/10/13/five-single-origin-coffees-to-try-this-winter/,/blog/five-single-origin-coffees-to-try-this-winter/,0,301

In WordPress, open Tools → Redirection → Import/Export, choose the file and import it. On the command line, wp redirection import redirects.csv --format=csv does the same. Our import reported 74 redirects created.

Before importing a few hundred redirects into the live site, create a backup. A wrong pair sends visitors to the wrong post, and a backup lets you undo the whole batch at once.

Step 5: Check the redirects

Open a few old URLs in a private browser window, or check them all with a link checker that reads URLs from a file (the old paths from column F). In our test, every one of the 74 old URLs that returned 404 after the change now answered with 301 Moved Permanently and the new /blog/ address. A web server can use the same pairs: for Nginx, turn each row into rewrite ^/old-path/$ /new-path/ permanent;.

Keep before.csv and after.csv with the backup. If someone reports a broken link a year later, they show which post the old URL belonged to.

With an AI agent

An AI agent connected through the WordPress MCP Adapter (see connecting Claude Code to WordPress) can make both exports and build the map:

Export all published posts with ID and permalink. I'm going to change the
permalink structure; after I tell you it's done, export them again, match the
two files by ID and give me a Redirection CSV with old path, new path, 0, 301
for every URL that changed.

In our run, the agent called rsl-ie/export-start twice with export_type: post, the filter post_status = publish and the fields ID and permalink. Both exports had 74 rows. It matched them by ID, reported 74 changed URLs and wrote the four-column CSV, which matched the one from the spreadsheet row for row.

FAQ

Not reliably. In our test, changing the structure from dated URLs to /blog/%postname%/ left all old URLs with a 404. A redirect map makes the redirects explicit.

Should I use 301 or 302 redirects?

Use 301 for a permanent change of URL. It tells search engines to replace the old URL with the new one in their index.

Yes, if you have a backup from before the change: restore it on a staging copy and make the before export there. Without one, an old sitemap or a crawl from an SEO tool can give you the old URLs, but you’ll have to pair them by slug instead of ID.

Do I need a redirect plugin?

No. The same pairs work as server rules for Nginx or Apache. A plugin is easier to manage from WordPress and logs 404s, so you notice URLs the map missed.

What about pages and WooCommerce products?

Export each post type that changes with ID and Permalink, both before and after, and build the map the same way. Product URLs change when you change the product base in Settings → Permalinks.

Get the free plugin on WordPress.org.

Dmitriy
About author

Dmitriy

WordPress Developer with 15+ years of commercial experience. Elite Author on ThemeForest and creator of custom WordPress plugins. Passionate about clean code, performance optimization, and building useful tools for the WordPress community.

JOIN THE CONVERSATION

Comments 0

Have a question or a tip to share? Leave it below.

Leave a comment

Your email address will not be published. Required fields are marked *

We store your name, email and comment to show and moderate it; your email is never published. Spam protection is provided by Cloudflare Turnstile and profile pictures by Gravatar. See our Privacy Policy.


Try the plugin with no risks!

New users get 1 month with access to all premium features. Experience the most powerful WordPress data engine today.

Download Now
Get PRO for FREE