Legacy Knowledge Base
Published Jul. 2, 2025

FriendlyURLMapper's Patterns and Matchers

Written By

Cristina Rodriguez

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

Legacy Article

You are viewing an article from our legacy "FastTrack" publication program, made available for informational purposes. Articles in this program were published without a requirement for independent editing or verification and are provided"as is" without guarantee.

Before using any information from this article, independently verify its suitability for your situation and project.

Issue

  • My friendlyURL portlet is not parsing correctly some of my URLs.
  • Sometimes it is not clear which kind of pattern we must define in routes.xml when implementing a module to make URLs friendly (see additional information about this implementation).
  • For example, if my routes.xml looks like:
    <routes>
      <route>
        <pattern>/{groupId}/{articleURLTitle}</pattern>
      </route>
    </routes>
  • The following URL is not going to be parsed correctly:
    http://localhost:8080/detail/-/content/20125/test.cc
  • And we can see in the log a message like this one (if the DefaultFriendlyURLMapper class' log level is configured to WARN):
    2021-07-26 14:46:06.891 WARN  [http-nio-7100-exec-10][DefaultFriendlyURLMapper:150] No route could be found to match URL /20125/test.cc
  • This is because the pattern defined in routes.xml is not correct, so it makes Liferay's choose an unsuitable matcher.

Environment

  • Liferay DXP

Resolution

  • It is important to know which kind of URLs your friendlyURL portlet is going to handle, since the patterns defined in file routes.xml are the key to apply the correct matcher for them.
  • Liferay's available matchers are:
  • Each of them define their specific matching rules: for example, DefaultMatcher does not allow the URL to contain dots (".").
  • The logic applied to use one or other is defined here
  • In the previous case, since the pattern does not include a colon (":"), the DefaultMatcher is set. And since this matcher "rejects" URLs including dots:
     if ((c == CharPool.SLASH) || (c == CharPool.PERIOD)) {
    return false;
    }
    Our URL http://localhost:8080/detail/-/content/20125/test.cc is not parsed.
  • To get our URL including dots parsed, we should define for example the following pattern:
    <pattern>/{groupId}/{templateKey}/{articleURLTitle:[^/]+}</pattern>

    So the NotSlashMatcher is selected and the parsing does no reject the dots.

     

Additional Information

 

Did this article resolve your issue ?

Legacy Knowledge Base