Look hereOn the Admin sidebar, go to Stores > Settings > Configuration > Catalog > Catalog > Search Engine Optimizations
and set Use Categories Path for Product URLs
value to No
. Remember to flush Magento cache.
More info is documentation: https://docs.magento.com/m2/ce/user_guide/catalog/catalog-urls.html#configure-catalog-urls Set “Use Categories Path for Product URLs” to “No”