Canonical Url is the best solution for duplicate urls in your website. It helps you deal with unwanted urls or query strings by adding the meta tag of the main url. Then google will keep only the url you want in its index and your site will not be considered as a spam content anymore.