cancel
Showing results for 
Search instead for 
Did you mean: 

How do I export my URL rewrite/redirect data

SOLVED

How do I export my URL rewrite/redirect data

I need to view all the URL rewrites & redirects in place.  Is there a way in the Admin Console to dump these to a CSV file so that I can view them en masse?

1 ACCEPTED SOLUTION

Accepted Solutions

Re: How do I export my URL rewrite/redirect data

Thanks.  I was trying to avoid having to get a developer involved or getting access to the database.  I can write a PHP program to do it myself.  If I had access to the DB, I would likely just use PHPMyAdmin to dump the table to a CSV.  I have since discovered the client has Firebear Import/Export on their installation. I can use that to dump the table I believe. Going to play around with it today.

Thanks again!

View solution in original post

2 REPLIES 2

Re: How do I export my URL rewrite/redirect data

Hello @jimjahodso001d 

 

In Magento 2, exporting URL rewrite/redirect data isn't available directly via the admin panel, but there are workarounds using either the command line interface (CLI) .

 

Create a custom PHP script to extract the data from the database and export it as a CSV file.

<?php

require_once 'app/bootstrap.php';
use Magento\Framework\App\Bootstrap;

$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();


$urlRewriteFactory = $objectManager->get('Magento\UrlRewrite\Model\UrlRewriteFactory');
$connection = $objectManager->get('Magento\Framework\App\ResourceConnection')->getConnection();

$sql = "SELECT * FROM url_rewrite";
$result = $connection->fetchAll($sql);


$csvFile = fopen('url_rewrite_collection_export.csv', 'w');
fputcsv($csvFile, ['URL Rewrite ID', 'Store ID', 'Request Path', 'Target Path', 'Redirect Type', 'Is Autogenerated']);


foreach ($result as $row) {
    fputcsv($csvFile, $row);
}

fclose($csvFile);

echo "URL Rewrites exported in CSV file successfully!";

?>

​Hope it helps ! 

If you find our reply helpful, please give us kudos.

 

A Leading Magento Development Agency That Delivers Powerful Results, Innovation, and Secure Digital Transformation.

 

WebDesk Solution Support Team

Get a Free Quote | | Adobe Commerce Partner | Hire Us | Call Us 877.536.3789

 

Thank You,


WebDesk Solution Support Team
Get a Free Quote | Email | Adobe Commerce Partner | Hire Us | Call Us 877.536.3789


Location: 150 King St. W. Toronto, ON M5H 1J9

Re: How do I export my URL rewrite/redirect data

Thanks.  I was trying to avoid having to get a developer involved or getting access to the database.  I can write a PHP program to do it myself.  If I had access to the DB, I would likely just use PHPMyAdmin to dump the table to a CSV.  I have since discovered the client has Firebear Import/Export on their installation. I can use that to dump the table I believe. Going to play around with it today.

Thanks again!