cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 2 Category url rewrite is not working

Magento 2 Category url rewrite is not working

After migration by using ubertheme, my category url is not working. Its showing all category urls are like below http://domain.com/catalog/category/view/s/trouvez-le-fauteuil-ou-canape-chesterfield-fait-pour-vous/...

Can you pleas help me how can i change it to seo format?

I have tried reindexing via ssh and also enable seo url for category and product from Configuration/catalog/SEO tab.

I am using magento 2.1.0

Thanks in advance.

Problem solved? Click Kudos and "Accept as Solution".
200+ Magento 2 Extensions for Enhanced Shopping Experience.
11 REPLIES 11

Re: Magento 2 Category url rewrite is not working

did you resolve this because im having the same issue, also getting .html.html in my rewrites ....

Re: Magento 2 Category url rewrite is not working

I am having a double suffix issue - like .html.html

And to rewrite you have to change the product and save or change the category product listings and save.

Change product and save did not work for me. I even changed the name of the product. and the url would not change

So I deleted the product urls

Change Category products (subtract product and then save and then add and save again) created  urls again but with the double suffix.

So there is a bug here

 

Sam

Re: Magento 2 Category url rewrite is not working

Hi @rich888 and @samreg
I have export the table url_rewrite and done find(.html.html) and replace with (.html)
I know this is not a solution but no one is answering our problem in this community and not finding the proper solution.
Thats why i am asking you to done like this.

 

Sorry

Problem solved? Click Kudos and "Accept as Solution".
200+ Magento 2 Extensions for Enhanced Shopping Experience.

Re: Magento 2 Category url rewrite is not working

I know this has been out there for a while but I am having the same exact issue.  I have made just about every seo-url related configuration adjustment I can find to no avail.  I have even truncated the url tables and that doesn't work.  I am at a loss and hope anyone has suggestions.

 

Product URL is

http://159.203.79.4/catalog/category/view/s/product-key/id/10/

ur key is set to product-key

 

Product URL is set to ".html"

category suffix is blank

Create Permanent Redirect URLs if URL key is changed is set to "yes"

 

I have Magento 2.1.1 installed on NGINX (Digital Ocean Droplet) with Serverpilot LAMP installed.

 

Any help would be greatly appreciated.

Re: Magento 2 Category url rewrite is not working

I'm having the same issue in 2.1.1.  URL Rewrites still work fine for old products I imported but now they are not showing up for a lot of my new products.  All the settings are enabled for URL Rewrites.

 

I think it may have something to do with existing URL names being in the database too.

 

For awhile when importing if you had the same name in the url_key column in an import file of an existing product Magento would not accept the import.  After the last couple releases Magento now accepts the import anyway but I wonder if this causes conflict.

 

If I have a product with URL Rewrite named "Blue Lamp Shade" and I import a product with url_key "Blue Lamp Shade" Magento should automatically append a -1 to the second one imported so its "Blue Lamp Shade-1" or something.  

 

This should have been done by default in the beginning.  I don't know what Magento 2 does when importing products with same url keys.

Re: Magento 2 Category url rewrite is not working

The tool you have used did not transfer url_key column on Products table. You should do it manually or using other tool to do.

 

Re: Magento 2 Category url rewrite is not working

Did you ever figure this out?

Re: Magento 2 Category url rewrite is not working

I am facing this issue in Magento 2.1.7. Whenever I try to save the product or category, it is throwing an error "URL key for specified store already exists."

Please let us know if anyone has a solution. 

Re: Magento 2 Category url rewrite is not working

Found a working solution in this link https://magento.stackexchange.com/questions/169352/magento-2-url-key-for-specified-store-already-exi...

Please note that don't do the change directly in vendor file. Please write your own plugin/preference to overwrite doReplace method. For a quick try, you can replace the code directly and check if it is working.

In the file 

\vendor\magento\module-url-rewrite\Model\Storage\DbStorage.php

Replace 

protected function doReplace($urls)
    {
        foreach ($this->createFilterDataBasedOnUrls($urls) as $type => $urlData) {
            $urlData[UrlRewrite::ENTITY_TYPE] = $type;
            $this->deleteByData($urlData);
        }
        $data = [];
        foreach ($urls as $url) {
            $data[] = $url->toArray();
        }
        $this->insertMultiple($data);
    } 

With

protected function doReplace($urls)
{
    foreach ($this->createFilterDataBasedOnUrls($urls) as $type => $urlData) {
        $urlData[UrlRewrite::ENTITY_TYPE] = $type;
        $this->deleteByData($urlData);
    }
    $data = [];
    $storeId_requestPaths = [];
    foreach ($urls as $url) {
        $storeId = $url->getStoreId();
        $requestPath = $url->getRequestPath();
        // Skip if is exist in the database
        $sql = "SELECT * FROM url_rewrite where store_id = $storeId and request_path = '$requestPath'";
        $exists = $this->connection->fetchOne($sql);

        if ($exists) continue;

        $storeId_requestPaths[] = $storeId . '-' . $requestPath;
        $data[] = $url->toArray();
    }

    // Remove duplication data;
    $n = count($storeId_requestPaths);
    for ($i = 0; $i < $n - 1; $i++) {
        for ($j = $i + 1; $j < $n; $j++) {
            if ($storeId_requestPaths[$i] == $storeId_requestPaths[$j]) {
                unset($data[$j]);
            }
        }
    }
    $this->insertMultiple($data);
}

If it is working for you please give Kudos and Accept it as a solution.