I cannot figure out what settings would prevent this from happening. Also cannot figure out how to fix the urls that have been set this way already. Thanks Sam
-
For reference: the question has been asked already but does not have an accepted answer yet at magento.stackexchange.com/q/121096/243 - did you also migrate products from Magento 1?– Fabian SchmenglerCommented Sep 10, 2016 at 18:57
-
I IMPORTED the products - but not from a magento site. Also - good point - only the imported products have this double suffix problem. Also it seems products that are in multiple categories has this problem. I can go into the table and clean once - but if I dont know why it is happening it will happen again.– samregCommented Sep 11, 2016 at 23:57
3 Answers
We fixed the URL's like this:
- Remove all product related rewrites from url_rewrite table
- Mass update all products in admin (select all, update, set website as default)
- If problem still exists, run this MySQL command:
UPDATE url_rewrite SET request_path = REPLACE(request_path, '.html.html', '.html')
WHERE url_rewrite.request_path like '%html.html';
Then clear the caches.
-
i would prefere it with a where condition like WHERE url_rewrite.request_path like '%html.html'– ZFNerdCommented Oct 4, 2018 at 7:14
-
@ZFNerd I'm sure your solution is better as I'm no MySQL master... If you could share the whole command that would be great.– WebninjaCommented Oct 5, 2018 at 7:17
This is more of an addition to @Webninja's answer, as his steps might solve the issue for others. Consider this a work-around and not a fix. Since it's a known bug in Magento 2.
In our case the mass update caused the double suffix to re-appear after saving a product or category, so the URLs were generated incorrectly. Our products were also imported from a Magento 1.x install.
Also the UPDATE
-query mentioned in his post didn't work, due to duplicate entry errors.
So, what I did was the following:
- Remove all product related rewrites from url_rewrite table (
DELETE FROM url_rewrite WHERE entity_type = 'product';)
- Remove the Product URL suffix (.html, in my case) and leave the field blank in stores > configuration > catalog > catalog > search engine optimization;
- Mass update all products in admin (select all, update attribute, check the box underneath 'Add product to website')
- In case mass update gives errors ('something' already exists) you can also save each main category (not root, one or two levels (depending on your setup) underneath) seperately. The URLs will also be regenerated then.
Now the URLs are correctly generated at each save of a product or category.
This is happening because of url rewrite management module.
For more information, go to Magento 2 Admin -> Marketing -> SEO & Search -> URL Rewrites.
you can change Request path.
You can find the module at
/vendor/magento/module-catalog-url-rewrite/
-
Where would I find the request path ? I can see Product url suffix, cat url suffix, use cats path for product urls (mine is NO), Create permanent redirect for urls (Mine YES). Canonical Links ? Mine Both NO– samregCommented Sep 10, 2016 at 21:18