It’s quite common for a website to have multiple unique URLs that lead to the same content. A really common one is when the www version of a site shows the same content as the non-www version of the website.
Most website’s Home page is set up and accessible as index.html or when upper and lowercase and URLs leads to the same pages. Ideally we wouldn’t even run across any of these alternate versions which is why Google recommend picking one URL format and using it consistently across your website. In common, Google discover all sorts of URLs leading to the same content for search, it doesn’t make much sense to index and show all of these versions, so google try to pick one and focus on particular version/page.
So, how does Google pick the canonical URL? Google try to pick the canonical URL by following two general guidelines.
First which URL does it look like the site wants us to use, so what is the site’s preference mentioned in Google Search Console and Secondly, which URL would be more useful for the user, in that case google look at a number of things that includes, the link rel canonical annotation which sites can use, but also redirect internal linking which URL is in a sitemap file.
So if you’re a site owner and you have a drawn preference regarding URLs that you want to have shown to users in search, first of all you should make sure that you use those preferences consistently across your website, ideally search engines wouldn’t even be able to stumble across any of those alternatives, if you have a preference and stick to it along that line make sure that all of the canonicalization factors that we mentioned are similarly aligned make sure that internal links use your preferred URL format. Make sure that sitemap files lists only preferred URLs and rel=canonical link elements match these pages.