It appears the direct URL for compare is as follows
# compare URL, where ref_source and ref_target can be commit SHA, tag, or branch
https://${gitlab_host}/${repo_path}/-/compare/${ref_target}...${ref_source}
# tag example 1, comparing tag v1.5.1 to master
https://${gitlab_host}/${repo_path}/-/compare/v1.5.1...master
# tag example 2, comparing tag v1.5.1 to tag v1.5.2
https://${gitlab_host}/${repo_path}/-/compare/v1.5.1...v1.5.2
# commit example 1, comparing commit SHA to master
https://${gitlab_host}/${repo_path}/-/compare/f6098082f...master
# commit example 2, comparing commit SHA to another commit SHA
https://${gitlab_host}/${repo_path}/-/compare/f6098082f...2b8daf28
To compare a single file across two commits, one needs to get a blob id of the file first, and append it to the compare url following a octothorp (#); gotta find a way to get that id though
# compare URL, where ref_source and ref_target can be commit SHA, tag, or branch, and file_blob
https://${gitlab_host}/${repo_path}/-/compare/${ref_target}...${ref_source}#${file_blob}
And the compare UI can be reached at https://${gitlab_host}/${repo_path}/-/compare, where you can select source and target refs via drop-down.
You first need to get the sha1 digest of the file path you are interested in (for instance with the sha1sum command). You can then build the URL to display the diff between two git ref (i.e. branch names or commit hash or tags) as follows:
The page will also display other diffs, not just the one you are interested in. But it will move you right where the diff of the file starts and you can ignore the rest.
go the list of commits (in the sidebar: Repository -> Commits), from where you have the SHA of any given commit (there's the copy button on right) handy;
go the the compare tool (in the sidebar: Repository -> Compare), and at the top, in source and target, past the SHA strings of the two commits you want to compare.