Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Sling Reverse Mapping not working?

Avatar

Level 3

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:

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:

 

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?

5 Replies

Avatar

Level 3

This doesn't use /etc/map at all, which will mean our instance wouldn't support a proper multi-tenant set up and we'll run into content collisions... or am I missing something?

 

e.g., if you follow along here- it's encouraged to use /etc/map for this configuration and to avoid adding mappings in the jcr resolver as it's instance wide: Configure Sling Mapping for Resource Resolution in Adobe Experience Manager — Deep Dive (albinsblog....

Avatar

Level 3

Just tried this in my publishing instance and it has no effect.

 

URLs are still being rendered as /content/mysite/path/to/page.html

Avatar

Level 10

@dylanmccurry  we also faced the same issue and got it solved by below change. In the below internalRedirect can you reverse the params. Hope this works

 

sling:internalRedirect="[/content/mysite/$1,/$1]"

 

Change 

sling:internalRedirect="[/$1,/content/mysite/$1]" 

Avatar

Level 3

This doesn't seem to have any effect- the URLs on the page are still being generated with the full content path.

 

In your dispatcher, are you sending the full content path to the publisher or a shortened version?

 

HOWEVER- when I make this change, I see this behavior in the jcrresolver on my publishing instance:

 

Input: /content/mysite/pattern-library/home/teaser.html

Map: Primary: http://test.mysite-local.com/pattern-library/home/teaser/. Other candidates: /content/mysite/pattern-library/home/teaser.html. (this looks correct to me)

 

Input: http://test.mysite-local.com/pattern-library/home/teaser.html

Resolve:  JcrNodeResource, type=cq:Page, superType=null, path=/content/mysite/pattern-library/home/teaser (this looks correct to me)

 

It appears that the HTML output is ... cached somewhere?  Does the publish instance hold onto the computed HTML and not update it or something?

 

When I visit this page: http://test.mysite-local.com/pattern-library/home/, I see a link to the above Teaser page, but it's: http://test.mysite-local.com/content/mysite/pattern-library/home/teaser.html