Handle links without .html extension | Community
Skip to main content
Level 3
November 13, 2015
Solved

Handle links without .html extension

  • November 13, 2015
  • 2 replies
  • 5028 views

We have a dialog to select pages or assets from the content tree using the xtype pathfield. The purpose of the selection is to create a link on a page. Since assets are saved with the extensions, and pages aren’t, the link correctly directs the user to the assets, but not to the pages (because the page url doesn’t have the HTML extension).

 

These are the solutions we considered so far::

1 - linkPattern property in the dialog, to automatically append the HTML extension to the selected node. The problem is that it is also applied to assets, resulting in a wrong path (e.g. /content/dam/mysite/photo.jpg.html).

2 - Rewrite URL for page requests, using Apache (/content/mysite/home -> /content/mysite/home.html). It would fix the problem, but since we have a shared environment, we try to avoid  any solutions that may affect other sites.

3 - Using https://sling.apache.org/documentation/the-sling-engine/mappings-for-resource-resolution.html. It would map extensionless urls and redirect to the correct link with the HTML extension. The mapping would be done only under this site.

4 - Create a workflow triggered by page creation. It would set a vanity url to the same path without the extension.


It there a better solution to solve our problem? The best would be something simple to configure (one point) and restricted to the site structure.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by kautuk_sahni
Content backfill required

2 replies

edubey
Level 10
November 14, 2015

Hi,

I guess the simplest solution is you can take care of this at development side in JSP or Sightly file. Below code shows using JSTL in JSP

<c:choose> <c:when test="${(fn:startsWith(listLink,'/content/dam')) || (fn:contains(listLink,'.'))}"> <c:set var="listLink" value="${listLink}"/> </c:when> <c:otherwise> <c:set var="listLink" value="${listLink}.html"/> </c:otherwise> </c:choose>
kautuk_sahni
Community Manager
kautuk_sahniCommunity ManagerAccepted solution
Community Manager
November 16, 2015
Content backfill required
Kautuk Sahni