301 is an HTTP status code when a browser receives that status code in the HTTP response, the browser expects a location URL on the same HTTP response. As soon as the browser gets 301 as HTTP status code it permanently redirects to the response location URL.
When to use 301?
When we have changed the URL pattern to a new URL we should do a permanent redirect (301) on old URLs
A canonical URL helps us fix duplicate content issues. When we have multiple URLs for the same content then it becomes an issue for SEO. Multiple URLs compete with each other for index rank. To fix this issue we can use canonical URLs.
The approach is to tell the crawler bot that we have one unique URL for the content. If we consider following example then it will be easier for us to understand.
Examples of Canonical URL
If we have above two URLs pointing to the same content then it’s a duplicate content issue for SEO. To fix this issue we can use a canonical tag like below:
<link rel="canonical" href="https://upokary.com/health-benefits-of-cabage" />
When to use Canonical URL?
When we have multiple URLs for the same content we should use canonical tag.