Magento 2 – Remove Parent Categories Slug from Subcategory URLs

categorymagento-2.1magento2

I want to remove the trailing category in magento 2

http://magento2.dev/accessories/tops-women.html
http://magento2.dev/accessories/tops-women/jackets-women.html

instead I want

http://magento2.dev/tops-women.html
http://magento2.dev/jackets-women.html

Best Answer

We can configure it by URL Rewrites

  1. Go to Magento 2 Admin -> Marketing -> SEO & Search -> URL Rewrites

  2. Find the path by searching Request path column.

  3. Remove the cache php bin/magento cache:clean.

  4. Refresh the front-end, click the main menu category then you can see the configured path.

Example i have modified.

Request path men/tops-men/tees-men.htm

Modified path tees-men.htm

Or

You Can Build category URL path by

\vendor\magento\module-catalog-url-rewrite\Model\CategoryUrlPathGenerator.php 

Modify getUrlPath($category) by Magento Plug-in feature.

Hope this helps.