如何在AEM中将页面重定向到其别名URL? [英] How to redirect the pages to their alias URLs in AEM?
问题描述
我们计划通过语言副本为翻译后的页面使用 sling:alias
属性,以便可以通过翻译后的URL访问翻译后的页面。
We are planning to use sling:alias
property for the translated pages through language copy so that the translated pages could be accessible through the translated URLs.
例如
英语页面- / content / site / en / test-page
语言副本- / content / site / es / test-page
-它具有sling:alias(páginade prueba)
Language copy- /content/site/es/test-page
- It has the property sling:alias (página de prueba)
别名URL- / content / site / es /páginade prueba
现在我们可以使用别名URL来访问它,但在其他地方仍然有使用 / content / site / es / test-page
URL的链接。因此,我们需要一个重定向规则,以便所有 / content / site / es
下的页面都重定向到其别名URL页面。
Now we are able to access it using the alias URL but we still have links in different places that use "/content/site/es/test-page
" URL. So we need a redirect rule in place so that all of these pages under /content/site/es
redirect to their alias URL pages.
我们如何实现这一目标?
How can we achieve this?
推荐答案
我们通常实现以下解决方案:
We usually implement a solution like this:
- 如果请求页面,我们将检查页面组件中所请求的url是否与resourceResolver.map(request,path)相同(这将返回带有别名路径的URL)。如果不是,则将永久重定向发送到别名路径。
- 我们在代码中生成的链接都将应用.map调用(中央实用程序类或服务)。
- 我们还添加了用于检查链接的重写器-请参见 https://helpx.adobe.com/zh-cn/experience-manager/using/aem63_link_rewriter.html 作为步行槽。
- If a page is requested we check in the page component if the requested url is the same as resourceResolver.map(request, path) (this returns a URL with the alias path). If not, we send a permanent redirect to the alias path.
- Links that we generate in our code all get the .map call applied (central utility class or service).
- We also add a link rewriter that checks the same - see https://helpx.adobe.com/experience-manager/using/aem63_link_rewriter.html for a walktrough.
HTH,
奥利弗(Oliver)
HTH, Oliver
这篇关于如何在AEM中将页面重定向到其别名URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!