Best practice for dealing with shopify canonical url mess

What is the best practice for dealing with “no internal links to canonical URLs” SEO issue. Linking to the canonical URL is not a viable solution for me so I was considering using 301 redirects to the canonical URL from any non canonical URL.

If the best practice is to 301 redirect to the canonical URL, is there a way to automate this with liquid/shopify API?

Would something like this be optimal?

{% if template ==‘product’ and page.url != product.url %}{% endif %}

or is there a better way of doing it since meta refresh is apparently looked down upon in SEO.