1. Home
  2. Knowledge Base
  3. How to Create & Edit Redirects Using CSV

How to Create & Edit Redirects Using CSV

Rank Math allows you to import redirections in multiple ways, but using CSV files for importing redirections can be helpful when you need to create/edit/delete redirections at a scale or if you’d like to collaborate with a team in managing the redirections of your website.

In this knowledgebase article, we will show how Rank Math’s PRO and Business users can make use of the CSV Import & Export feature to create or edit redirects at scale.

1 Creating CSV with Redirection Rules

To use this feature of Import & Export CSV feature Rank Math to create redirections, we’ll need to first get started with creating the CSV. You can create a CSV by following the exact steps given below.

1.1 Open Spreadsheet

To create a CSV file, you can open a Spreadsheet editor of your choice. We recommend using Google Sheets if you wish to collaborate with your team.

1.2 Adding Columns

To help Rank Math understand the data you’re referring to with CSV, you’ll need to create a header row (which is the first row) with the following column names: id, source, matching, destination, type, category and status.

Create CSV for importing redirects

The order of the columns does not matter, but for Rank Math to create a new redirection from CSV, it should have at least the source and destination column.

1.3 Adding Values for Columns

Under each designated column you can add only a specific set of values such as:

  • id – You can add the ID of the redirection under this column to edit an existing redirection. If no ID is used, Rank Math will create a new redirection.
  • source – Enter the URL or URL(s) from where you want your visitors to be redirected from.
  • matching – Add the matching type here to let Rank Math know how the pattern in the source column should be matched with. The accepted values are exact, contains, start, end and regex.
  • destination – Enter the URL where you want your visitors to be taken to after the redirection
  • type – Enter the redirection type under this column. The accepted values are 301, 302, 307, 410 and 451. Rank Math by default considers the status to be 301.
  • category – You can enter a category for your redirection under this column. Adding a value to this column is optional. If you add a Redirection category under this column that you haven’t already created on your website, then a new Redirection category will be created.
  • status – The accepted values are active and inactive. If you leave the field blank, Rank Math by default considers the status as active.

Here is an example of a filled spreadsheet.

CSV example for redirections

1.4 Saving Spreadsheet as CSV

Once you’re done with adding the redirection rules, you’ll need to save the spreadsheet as a CSV file to your computer.

2 Importing CSV

Once you’ve created a CSV file, you can follow the below steps to upload the CSV file for creating new redirects on your website.

2.1 Navigate to Redirections

Head over to Rank Math > Redirections inside your WordPress Admin area. If you’re unable to find Redirections under the Rank Math menu, then you’ll need to enable the Redirections module under Rank Math > Dashboard.

Navigate to Redirections Manager in Rank Math

2.2 Choose Import & Export

In the Redirections page, click the Import & Export option available at the top of the screen.

Choose Import & Export in Redirections

2.3 Upload Your CSV File

Under the Import tab, click the Choose File button to upload the CSV file you’ve created.

Choose CSV file to upload

2.4 Import Redirects from CSV

Now click the Import CSV button, and in the confirmation prompt click OK. Rank Math will now start creating redirections from the imported CSV file, and it takes a few minutes to complete depending upon the size of the file.

Importing CSV to create Redirections

Once the CSV import is complete, you’ll see a success message with the number of new redirections created from the imported CSV file.

CSV import success message

3 Multiple Source URLs

Rank Math supports adding multiple URLs in the Source field. You can also use the same feature in the CSV file by adding the value in the JSON format. The value must be an array of objects with pattern and comparison properties, as shown below.

[
    {
        "pattern": "/first-blog-post/",
        "comparison": "exact"
    },
    {
        "pattern": "/second-blog-post/",
        "comparison": "exact"
    }
]

Since the URL matching type is passed by the comparison property here, any value you’ve under the matching column of the CSV will be ignored in this case. While adding JSON to the CSV file, ensure that they are in the minified form as shown below.

Adding multiple URLs in the Source field using JSON format

Now you can import the CSV in the Import tab of Rank Math’s Redirection Manager and your redirections will be imported.

4 Editing Existing Redirects

Apart from creating new redirects using CSV, you can also use this feature to edit the existing redirects using CSV. In your CSV file, enter the ID of your existing redirection under the id column and enter the redirection rule you want to update with. To find the ID of your redirection, click the Edit option available under your redirection.

Edit a redirection

Now while you’re on the Edit screen, you can find the URL of the page on the address bar and it would look something like this.

https://rankmath.local/wp-admin/admin.php?page=rank-math-redirections&redirection=43&...

From the URL, you can notice a number available after the query parameter redirection, and it is the ID of the redirection. So in this example, 43 is the redirection ID, and it would be different for each redirection. You should use this redirection ID in the CSV to edit the existing redirection.

5 Editing Redirects at Scale

The previous method of editing existing redirection could be useful only in limited cases, as it becomes tedious to find the redirection ID if you’ve too many existing redirects to edit.

The easiest way to edit existing redirects at scale is by exporting them in the CSV format, making the changes, and importing them back to Rank Math. This can be done exactly as shown below.

5.1 Navigate to Redirections Import & Export

At first, head over to WordPress Dashboard > Rank Math > Redirections > Import & Export.

Navigate to Redirections Import & Export

5.2 Export CSV

Now click the Export tab, and you’ll find different ways to export your redirections. It also includes an option to export redirections as CSV. Click the Export CSV button. Now all your redirections will be exported to your computer.

Export redirections as CSV

5.3 Edit CSV

Now open the CSV file in your spreadsheet editor. From the list of redirections, you can make the changes you need. Once you’ve made the changes, save the CSV file.

Modified Redirection data in CSV

5.4 Import CSV

Now click the Import Tab and upload the CSV file you’ve edited. Next, click the Import CSV button and choose OK in the confirmation prompt.

Import edited CSV

Now you can check the redirection you’ve modified with CSV in the edit screen to see if any changes have been reflected.

Redirection data updated

6 Deleting Existing Redirects

Similar to creating new redirections and editing existing redirections, you can also delete existing redirections using CSV. To do so,

6.1 Export Existing Redirects

Export your redirections by navigating to Rank Math > Redirections > Import & Export and choosing the Export CSV option under the Export tab.

Export existing redirections at CSV

6.2 Adding DELETE

To delete an existing redirect, add the DELETE value under the destination column against the redirection you wanted to delete, as shown below.

Deleting redirections using CSV

Note: The value DELETE is case sensitive and hence should be used in the same way.

6.3 Importing CSV

Now, save the edited CSV file to your computer and upload it in the Import tab. Next, click the Import CSV button and choose Ok in the confirmation prompt to allow Rank Math to delete the redirections marked with the DELETE value in the CSV file.

Once the redirections are deleted, a success message is shown with the number of redirections deleted. You can also check your Redirections Manager to see if Rank Math has deleted the redirection rules.

Redirections deleted using CSV in Rank Math

And, that’s it! We hope the article was helpful in using the Import & Export CSV feature of Rank Math to manage your redirections. If you’ve absolutely any questions on using CSV for creating/editing/deleting redirects with Rank Math, please free to reach our support team directly from here — we’re always here to help.

Still not using Rank Math?

Setup takes less than 5 minutes including the import from old SEO Plugin!

Buy PRO Version

Was this article helpful?

Still need help?

?

Submit Your Question

Please give us the details, our support team will get back to you.

Open Ticket