I want to remove url of prodcuts for a specific category. How can i remove specific category URL-REWRITE? using Query pro-grammatically

  • Did you resolve your query? – Shoaib Munir Jul 9 at 12:48
  • 1
    yes i done that let me past my answer – Asad Ullah Jul 10 at 5:47
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

  $resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
    $connection = $resource->getConnection();
    $tableName = $resource->getTableName('url_rewrite');
    try {
        $sql = "DELETE  FROM `url_rewrite` WHERE `entity_type` LIKE 'category' AND `target_path` LIKE '%id/234'";
    catch(Exception $e) {
        echo 'Message: ' .$e->getMessage();

here in querry target_path (%id/234) defines your category

  • 1
    Good to know that you have resolved it. +1 :) – Shoaib Munir Jul 10 at 6:02
  • 1
    thanks for your help man – Asad Ullah Jul 10 at 7:28

You can use this command to delete product URL for specific category

DELETE FROM url_rewrite WHERE target_path LIKE 'catalog/product/view/id/[PROD_ID]/category/[CAT_ID]'

where PROD_ID is your product id, and CAT_ID is the ID of category from which you need to delete URL.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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