Wrong URL generated

  Written by The Jahia Team
 
Developers
  url 404
   Estimated reading time:
7.1.2

The issue was the following one:

  1. Connection to the site: https://bo-jahia-vmoa2.mydomain.com/cms
  2. In this site, access the page: "Any Page"
  3. In this page, a "Preview" link should generate this URL:
    https://bo-agence-vmoa2.mydomain.com/cms/render/default/fr/sites/mykey/home.html?pdv=010101
  4. But the link returns a 404 error

Cause

The redirection was written as below:
 

<a href="${urlHostMoSAG}/cms/render/default/fr${renderContext.mainResource.node.resolveSite.path}/home.html?pdv=${entry.key}" 
    target="_blank" 
    class="nw-see-publication">Any Page</a>

 

Solution

The good practice is to use the <c:url> JSTL tag to handle URLs. This is explained in the development-best-practices documentation:

https://academy.jahia.com/documentation/digital-experience-manager/7.2/development/development-best-practices#Handling_URL

The good syntax is:

<c:url value="{urlHostMoSAG}/home.html" var="targetUrlMo">
    <c:param name="pdv" value="{entry.key}" />
</c:url>
<a href="${targetUrlMo}" target="_blank" class="nw-see-publication">