I am trying to implement a URL scheme similar to stack overflow's in django/python.
E.g. the pk is stored in the URL along with a slug of the title so for this question (id #4787731) the URL is
https://stackoverflow.com/questions/4787731/canonical-links-and-301-redirect-if-url-doesnt-match-slug
If I later change the title (or just put in some random crud into the url) then the site will still know which question I am after (by the ID) and will 301 redirect to the correct URL - e.g. try.
https://stackoverflow.com/questions/4787731/canonical-links-MODIFIED-URL
So
What is the best way to include canonical links in my pages such as
(can I use get_absolute_url)
Note - This question is similar but only addresses the case of generating the slug on the fly or statically.