Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.

For Resource Mapping, are regexes matched against full request URLs or only request paths?

Avatar

Level 7

In ResourceMapping, are patterns matched against full request URLs or request paths?

Also the "welcome pattern" example given in that page looks to be bogus:

For example, the:

Pattern ^[^/]+/[^/]+/welcome$

will trigger the:

Replacement /libs/cq/core/content/welcome.html.

to redirect a request:

http://localhost:4503/welcome

to:

http://localhost:4503/libs/cq/core/content/welcome.html

That pattern does not match either of /welcomelocalhost:4503/welcome, or http://localhost:4503/welcome.

Could please someone shed some light on what's going on how these patterns get evaluated?

3 Replies

Avatar

Level 7

So according to http://sling.apache.org/documentation/the-sling-engine/mappings-for-resource-resolution.html, these requests are "mingled" before being evaluated. There's an error in that page as well, though:

To accomplish this a path is constructed from the request as \{scheme\}/\{host.port\}/\{uri_path\}

This should be

To accomplish this a path is constructed from the request as {scheme}/{serverName}.{port}/pathInfo

According to this code block in the same page:

     
1 2 3 4 5 6 7 8 9 10 11 12 13
String path = request.getScheme + "/" + request.getServerName()+ "." + request.getServerPort() + "/" + request.getPathInfo();String result = null;for (MapEntry entry: mapEntries) {Matcher matcher = entry.pattern.matcher(path);if (matcher.find()) {StringBuffer buf = new StringBuffer();matcher.appendReplacement(buf, entry.getRedirect());matcher.appendTail(buf);result = buf.toString();break;}}

Avatar

Level 7

So according to http://sling.apache.org/documentation/the-sling-engine/mappings-for-resource-resolution.html, these requests are "mingled" before being evaluated. There's an error in that page as well, though:

To accomplish this a path is constructed from the request as \{scheme\}/\{host.port\}/\{uri_path\}

This should be

To accomplish this a path is constructed from the request as {scheme}/{serverName}.{port}/pathInfo

According to this code block in the same page:

     
1 2 3 4 5 6 7 8 9 10 11 12 13
String path = request.getScheme + "/" + request.getServerName()+ "." + request.getServerPort() + "/" + request.getPathInfo();String result = null;for (MapEntry entry: mapEntries) {Matcher matcher = entry.pattern.matcher(path);if (matcher.find()) {StringBuffer buf = new StringBuffer();matcher.appendReplacement(buf, entry.getRedirect());matcher.appendTail(buf);result = buf.toString();break;}}

Avatar

Level 7

So according to http://sling.apache.org/documentation/the-sling-engine/mappings-for-resource-resolution.html, these requests are "mingled" before being evaluated. There's an error in that page as well, though:

To accomplish this a path is constructed from the request as \{scheme\}/\{host.port\}/\{uri_path\}

This should be

To accomplish this a path is constructed from the request as {scheme}/{serverName}.{port}/pathInfo

According to this code block in the same page:

     
1 2 3 4 5 6 7 8 9 10 11 12 13
String path = request.getScheme + "/" + request.getServerName()+ "." + request.getServerPort() + "/" + request.getPathInfo();String result = null;for (MapEntry entry: mapEntries) {Matcher matcher = entry.pattern.matcher(path);if (matcher.find()) {StringBuffer buf = new StringBuffer();matcher.appendReplacement(buf, entry.getRedirect());matcher.appendTail(buf);result = buf.toString();break;}}