Editing canonical links without a module, contained in $head?
You need the Meta Tags module.

After you activate it, go to /admin/config/search/metatags/config/global and, under advanced, you can change the default canonical link.

Look at the path patterns used for PathAuto and prefix them with the desired base url.