Sling Reverse Mapping not working?
EDIT: I am noticing that it is working for certain types of fields, such as an image src-set attribute, but it is not working for an anchor's href attribute. What can I look for to see if this type of field is being skipped over somehow?
I am using the AEMaaCS Quickstart Jar.
I am following along with these two posts attempting to shorten (remove /content/mysite/) and strip html extensions from my website:
- Configure Sling Mapping for Resource Resolution in Adobe Experience Manager — Deep Dive (albinsblog.com)
- How to implement extension-less URL’s in AEM | by Albin Issac | Tech Learnings | Medium
I am running a local instance of Dispatcher following the guidelines here: Local Development Environment for AEM as a Cloud Service | Adobe Experience Manager
I have configured my hosts file as follows:
test.mysite-local.com 127.0.0.1
I am running dispatcher on port 8000, and am able to navigate to http://test.mysite-local.com:8000 and see this resolving to my local AEM publishing instance.
My content tree looks like this:
- content
- mysite
- en-us
- home
- ja-jp
- home
- pattern-library
- home
The intention is to canonicalize to something like:
- http://test.mysite-local.com/en-us/home/
- http://test.mysite-local.com/ja-jp/home/
- http://test.mysite-local.com/pattern-library/home/
I have configured my dispatcher rewrite rules to have this setup:
Include conf.d/rewrites/default_rewrite.rules
# Handle the landing page - send requests to / over to /en-us/home/
RewriteRule ^/$ /en-us/home/ [R=301,L]
# Mask the /content/mysite path - redirect URLs with this path to not have it
RewriteRule ^/content/${CONTENT_FOLDER_NAME}/(.*)(\.html)?$ /$1 [NE,L,R=301]
# Replace the .html with / - if URL is ending with .html, strip it and replace it with a /
RewriteCond %{REQUEST_URI} \.html$
RewriteRule ^/(.*).html$ /$1/ [R=301,L,QSA]
# Force a trailing slash if not present
RewriteCond %{REQUEST_URI} ^/(en-us|ja-jp|pattern-library)
RewriteCond %{REQUEST_URI} /+[^\.]+$
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
# Append the full content path + .html extension for those URL’s ending
# with a / before sending to publisher
RewriteCond %{REQUEST_URI} !^/$
RewriteRule ^/(.*)/$ /content/${CONTENT_FOLDER_NAME}/$1.html [PT,L,QSA]
# Pass through AEM's non content URLs accordingly (this is left as default)
RewriteCond %{REQUEST_URI} !^/apps
RewriteCond %{REQUEST_URI} !^/bin
RewriteCond %{REQUEST_URI} !^/content
RewriteCond %{REQUEST_URI} !^/etc
RewriteCond %{REQUEST_URI} !^/home
RewriteCond %{REQUEST_URI} !^/libs
RewriteCond %{REQUEST_URI} !^/saml_login
RewriteCond %{REQUEST_URI} !^/system
RewriteCond %{REQUEST_URI} !^/tmp
RewriteCond %{REQUEST_URI} !^/var
RewriteCond %{REQUEST_URI} (.html|.jpe?g|.png|.svg)$
RewriteRule ^/(.*)$ /content/${CONTENT_FOLDER_NAME}/$1 [PT,L]
And within AEM, I am configuring my /etc/map as follows:
/etc/map/http/test.mysite-local.com.8000
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="sling:Mapping"
sling:internalRedirect="[/content/mysite]"
/>
/etc/map/http/test.mysite-local.com.8000/redirect
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="sling:Mapping"
sling:match="(.+)$"
sling:internalRedirect="[/content/mysite/$1,/$1]"
/>
/etc/map/http/test.mysite-local.com.8000/reverse_no_html
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="sling:Mapping"
sling:match="$1/"
sling:internalRedirect="[/content/mysite/(.*).html]"
/>
Up until this point, when running dispatcher on port 8000, I can navigate to http://test.mysite-local.com:8000/en-us/home/ and I see the contents of this page.
HOWEVER: The issue is when I actually view components from my page. When I navigate to http://test.mysite-local.com/en-us/home/, this page as a Teaser component on it. The teaser is linking to `/content/mysite/en-us/home/child-page.html`.
Reverse mapping does not appear to be working correctly. What am I missing?

