Better SEO for external links in OpenCms Navigation
The Problem
If you put an external link into the OpenCms navigation the resulting link will target the external link file which then in turns redirects the surfer to the external page. This is bad if you really want to optimize your navigation for search engines, because search engines won’t see the real link inside the navigation.
The solution
You can use the following JSP snippet to get the real URL from a CmsJspNavElement.
// We assume that the variable "link" holds an CmsJspNavElement and // "cmsa" holds an CmsJspActionElement. // Prevent external links from beeing a redirect // therefore extract the real URL out of the file String fileUri = link.getResourceName(); CmsResource navResource = cmsa.getCmsObject().readResource(fileUri); if (navResource.getTypeId() == CmsResourceTypePointer.getStaticTypeId()) { CmsFile navFile = CmsFile.upgrade(navResource,cmsa.getCmsObject()); String externalLink = new String(navFile.getContents()); externalLink = externalLink.trim(); }
Further reading
Tags: JSP, OpenCms, SEO, Sourcecode, Tutorial
