0

I am trying to remove the .html.html from Products and Categories url.

I have gone procedure with the below steps after some research on this issue.

Stap 1.

SELECT * FROM `url_rewrite` WHERE `entity_type` LIKE 'product' AND `target_path` LIKE '%.html.html%' 

//Than delete all the result rows

UPDATE url_rewrite SET request_path = REPLACE(request_path, '.html.html', '.html') where entity_type="product" 


SELECT * FROM `url_rewrite` WHERE `entity_type` LIKE 'category' AND `target_path` LIKE '%.html.html%' 

//Than delete all the result rows

UPDATE url_rewrite SET request_path = REPLACE(request_path, '.html.html', '.html') where entity_type="category"

I have tried but when I run indexer:reindex the issue is remain same.

After that, I have go to the Magento 2 Admin -> Catalog -> SEO -> Product URL Suffix and removed the .htmlfrom field and Save Config.

I have tried but when I run cache:flush. And go to the Magento 2 Admin -> Products -> Catalog and select all the products and do Updated Attributes. When I go to the url_rewrite table and check all the URL has removed the single .html.

The issue with the new products when I create new product it's not adding the .html suffix, for that I have again go to the Magento 2 Admin -> Catalog -> SEO -> Product URL Suffix and added the .htmlin field and Save Config.

After Save Config all the products urls added again .html.html.

How I can check this issue so that the existing products has single .html and when I add new product it will add the .html suffix. Or where I can check in this in the Module:

/vendor/magento/module-catalog-url-rewrite/

Please help me out this issue.

I am still not receive any answer on this question.

2

After do many research for this question and can't get any success. I have solved this issue to edit the Model file of /vendor/magento/module-catalog-url-rewrite/ module.

I have overwrite the Catalog URL Rewrite Module model file:

/app/code/Magento/CatalogUrlRewrite/Model/ProductUrlRewriteGenerator.php

In this file I have overwirte the below function like below:

protected function generateForSpecificStoreView($storeId, $productCategories)
    {
        $categories = [];
        foreach ($productCategories as $category) {
            if ($this->isCategoryProperForGenerating($category, $storeId)) {
                $categories[] = $category;
            }
        }
        $this->productCategories = $this->objectRegistryFactory->create(['entities' => $categories]);
        /**
         * @var $urls \Magento\UrlRewrite\Service\V1\Data\UrlRewrite[]
         */
        $urls = array_merge(
            $this->canonicalUrlRewriteGenerator->generate($storeId, $this->product),
            $this->categoriesUrlRewriteGenerator->generate($storeId, $this->product, $this->productCategories),
            $this->currentUrlRewritesRegenerator->generate($storeId, $this->product, $this->productCategories),
            $this->getAnchorUrlRewriteGenerator()->generate($storeId, $this->product, $this->productCategories)
        );

        foreach ($urls as $key => $value) {
             $value->getRequestPath();

             $newURL=str_replace(".html.html", ".html", $value->getRequestPath(),$count);
             if ($count > 0) {
                $value->setRequestPath($newURL);
             }
        } 

        /* Reduce duplicates. Last wins */
        $result = [];
        foreach ($urls as $url) {
            $result[$url->getTargetPath() . '-' . $url->getStoreId()] = $url;
        }
        $this->productCategories = null;
        return $result;
    }

And now it's working fine for me.

  • @AnkitShah, please look the above answer. – mageDev0688 Apr 27 '17 at 6:12
  • @mageDev0688 your code gives fatal error: Call to private method Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator::getAnchorUrlRewriteGenerator() from context – Nirav Joshi Aug 26 '17 at 5:06
  • @Nirav Which version you using? – mageDev0688 Aug 26 '17 at 7:42
  • @mageDev0688 i just override your given code in my custom module. the error was generated because $this->getAnchorUrlRewriteGenerator()->generate($storeId, $this->product, $this->productCategories) this is a private method. so you cant use private method out of context. i just solved that error in my custom extension :) – Nirav Joshi Aug 26 '17 at 7:49
  • When I add this code and delete the url_rewrite table URL is not regenerated – Krunal Pandya Jul 20 at 5:13
0

The issue is due the '.hmtl' entry in 'catalog_product_entity_varchar' for url_path attribute. While importing the products we should omit .html for url_path attribute. As we set product suffix - .html in admin side(Catalog > Search Engine Optimization), the correct url with one .html will be created in url_rewrite table.

If you already import products with '.html' in url_path attribute, please do below steps to correct 2 .html issue.

  • UPDATE catalog_product_entity_varchar SET value = REPLACE(value, '.html', '') WHERE attribute_id = 125; // replace correct attribute id for product url_path attribute
  • Do reindex
  • GO go admin and save main category. This is regenerate url_rewrite for products under this category
  • delete from url_rewrite where entity_type = 'product' and redirect_type = 301; // Delete entries which is created for old urls

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.