Okay, i've fixed this. In some places the first parameter $page of tep_href_link was being supplied including the catalog subfolder. So i've tweaked tep_href_link to strip this out, and it now works. But thats a bit hacky so if you know of the root cause and proper fix for it, that would be appreciated.