Read this great reference for creating a csv for import but this was for Magento 1 and it states you only need store_id, id_path,request_path, target_path, options but these headers won't work for Magento 2.

In Magento 2 it looks like the entity_id is required and this would be painful indeed. Does anyone know what fields I need to import to get a massive amount of 301 rewrites into url_rewrites or a table that has paths and entity_id in it so I can cross reference?

Thank you.

3 Answers 3


If you can load your CSV file content then This is the way to import Bulk URL Rewrite:

Add below Code into script than run it.


    use Magento\Framework\App\Bootstrap;
    use Magento\Framework\App\Config\ScopeConfigInterface;
    use Magento\Store\Model\StoreManagerInterface;
    use Magento\Framework\Exception\LocalizedException;
    use Magento\UrlRewrite\Model\UrlFinderInterface;
    use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;

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

    $state = $objectManager->get('Magento\Framework\App\State');

    $scopeConfig = $objectManager->create('Magento\Framework\App\Config\ScopeConfigInterface');

    $_storeManager = $objectManager->create('Magento\Store\Model\StoreManagerInterface');
    $dataProcessor = $objectManager->create('Magento\Framework\Reflection\DataObjectProcessor');

    $storeId = $_storeManager->getDefaultStoreView()->getStoreId();    

foreach($data as $key => $rec)
    $urlRewrite = $objectManager->create(\Magento\UrlRewrite\Model\UrlRewrite::class);


    $model = $urlRewrite;
    $product['entity_type']      = $rec['entity_type'];
    $product['request_path']     = $rec['request_path'];
    $product['target_path']      = $rec['target_path'];
    $product['redirect_type']    = $rec['redirect_type'];
    $product['store_id']         = $rec['store_id'];

        ->setDescription("Imported Urls");


echo "Successfully Imported!";

$data is the data from your csv or file. which should have same name column as above imported.

entity_id is not required is you choose entity_type "custom"

Set appropriate path to include bootstrap for "include('../../../app/bootstrap.php');", I have added my script in "pub/script/vendor", So I have applied path like this.


I had to do this by exporting the url_rewrite database table then added my custom redirects and imported via phpMyadmin and works fine.


Simple Solution. Just create a csv with two columns

sku, product_websites

Then import it in smaller chunks of about 1000 products each. It should rewrite those product urls.

You can check if the url rewrite worked by going to marketing->url rewrites

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.