The ${currentPage.path}
variable will give you the path of the parent page to the current resource, but you should use the Externalizer to make this into a nice user-facing URL, (i.e. applying any mapping rules that you have in place & using the correct domain name, rather than the server name e.g. prod-server-123
)
i.e.
ResourceResolver resourceResolver = request.getResourceResolver();
Externalizer externalizer = resourceResolver.adaptTo(Externalizer.class);
String canonicalUrl = externalizer.publishLink(resourceResolver, "http", currentPage.getPath());
You can customise what the externalizer treats as the base URL via Felix, or via an osgi:Config
node in your repository. and read more on the official docs on the Adobe site.
(Note that the Externalizer is CQ5.5+)