获取当前网页URL在Adobe CQ5 Canonical链接(Get Current Page Url In Adobe CQ5 for Canonical Link)

在Adobe CQ5中有没有一种标准方式来获取当前页面的URL,以便在JSP头部创建自动规范链接?

基本上我们有一个对话框配置框,您可以覆盖规范链接,但默认情况下,如果它是空的,我想根据当前请求的原始URL路径构建链接。

头部的JSP在所有请求之间共享。

非常感谢

Is there a standard way in Adobe CQ5 to get the current page url in order to create automatic canonical links in the head of the JSP?

Basically we have a dialogue config box where you can override the canonical link, but by default if this is empty I want to construct the link based on the raw URL path for the current request.

The JSP for the head is shared across all requests.

Many thanks

最满意答案

${currentPage.path}变量会为您提供父页面到当前资源的路径,但您应该使用Externalizer将其设置为一个很好的面向用户的URL(即应用您已有的映射规则) &使用正确的域名,而不是服务器名称,例如prod-server-123 )

ResourceResolver resourceResolver = request.getResourceResolver(); Externalizer externalizer = resourceResolver.adaptTo(Externalizer.class); String canonicalUrl = externalizer.publishLink(resourceResolver, "http", currentPage.getPath());

您可以通过Felix或通过存储库中的osgi:Config节点自定义外部工具处理的基本URL。 并阅读Adobe网站上的官方文档 。

(请注意,Externalizer是CQ5.5 +)

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+)

更多推荐