Image V3 Component with Resource Mapping | Community
Skip to main content
New Participant
February 5, 2023
Solved

Image V3 Component with Resource Mapping

  • February 5, 2023
  • 2 replies
  • 1834 views

Hi all,

I am using image v3 component (aem core components v2.19.2) and created a custom image component based on the same. The OOTB AdaptiveImageServlet is loading the image renditions in the below URL format, 

 

Author:
/content/<project_path>/<page_path>/<component_path>/<component_name>.coreimg.<quality>.<width>.<extension>/<timestamp>/<filename>.<extension>

Publish:
/content/<project_path>/<page_path>/<component_path>/<component_name>.coreimg.<quality>.<width>.<extension>/<timestamp>/<filename>.<extension>

Because of the above implementation and the website sling mapping to shorten the URLs, the image paths are also shortened. So the images are not being displayed in publisher. The images are not accessible with the same URL format from the dispatcher as well which is a different issue altogether. 

 

But is there a way to exclude the images from being picked up by the sling mappings so that the complete URLs are available in publisher and the same can be accessed by dispatcher as well. 

 

Tried various regex patterns for sling:match but no luck. Completely blocked with this issue. Any help would be appreciated. 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by AlbinIs1

You should be able to handle this through the dispatcher PT rewrite rule; even though the URL is shortened from the publisher, the dispatcher can always send the complete path through the PT rule.

My assumption is you are following the latest dispatcher configuration structure; below is the sample PT rule configured on the rewrite file(additional conditions can be added based on the need)

 

RewriteCond %{REQUEST_URI} !^/apps/(.*) [NC] RewriteCond %{REQUEST_URI} !^/etc(.*) [NC] RewriteCond %{REQUEST_URI} !^/home/(.*) [NC] RewriteCond %{REQUEST_URI} !^/libs(.*) [NC] RewriteCond %{REQUEST_URI} !^/content(.*) [NC] RewriteCond %{REQUEST_URI} !^/system(.*) [NC] RewriteCond %{REQUEST_URI} !^/dam(.*) [NC] RewriteCond %{REQUEST_URI} !^/robots.txt [NC] RewriteCond %{REQUEST_URI} !^/(.*)/sitemap.xml [NC] RewriteRule ^/(.*) /content/test/$1 [PT]

 

Regards

Albin

https://www.albinsblog.com

2 replies

AlbinIs1Accepted solution
New Participant
February 6, 2023

You should be able to handle this through the dispatcher PT rewrite rule; even though the URL is shortened from the publisher, the dispatcher can always send the complete path through the PT rule.

My assumption is you are following the latest dispatcher configuration structure; below is the sample PT rule configured on the rewrite file(additional conditions can be added based on the need)

 

RewriteCond %{REQUEST_URI} !^/apps/(.*) [NC] RewriteCond %{REQUEST_URI} !^/etc(.*) [NC] RewriteCond %{REQUEST_URI} !^/home/(.*) [NC] RewriteCond %{REQUEST_URI} !^/libs(.*) [NC] RewriteCond %{REQUEST_URI} !^/content(.*) [NC] RewriteCond %{REQUEST_URI} !^/system(.*) [NC] RewriteCond %{REQUEST_URI} !^/dam(.*) [NC] RewriteCond %{REQUEST_URI} !^/robots.txt [NC] RewriteCond %{REQUEST_URI} !^/(.*)/sitemap.xml [NC] RewriteRule ^/(.*) /content/test/$1 [PT]

 

Regards

Albin

https://www.albinsblog.com

New Participant
February 15, 2023

Hi @albinis1 ,

Thanks for the reply and we have fixed in kind of similar ways now. Please find the dispatcher PT rewrite rule fix below,

 

# Rewrite image calls
RewriteCond %{REQUEST_URI} !^/content/experience-fragments
RewriteCond %{REQUEST_URI} !^/content/dam
RewriteCond %{REQUEST_URI} (.jpeg|.png|.svg|.jpg|.gif)$
RewriteRule ^/(.*)$ $aempath/home/$1 [PT,L]

arunpatidar
New Participant
February 6, 2023

Hi,

Can you share the Sling mapping here?

 

You can do the following:

You can restrict sling mappings with .html extension for apply only for page.

or 

Apache rewrite rules can also be written on the dispatcher for assets to resolve on AEM Publish.

Arun Patidar
shanky24Author
New Participant
February 6, 2023

Please find the sling mapping used below,

"map": { "jcr:primaryType": "sling:Mapping", "jcr:createdBy": "admin", "jcr:created": "Sun Feb 05 2023 14:40:30 GMT+0000", "sling:match": "$1", "sling:internalRedirect": "/content/we-retail/us/en/(.+)" }, "mapWithoutHtml": { "jcr:primaryType": "sling:Mapping", "jcr:createdBy": "admin", "jcr:created": "Sun Feb 05 2023 16:50:26 GMT+0000", "sling:match": "$1", "sling:internalRedirect": "/content/we-retail/us/en/(.+)\.html" }, "mapHomePage": { "jcr:primaryType": "sling:Mapping", "jcr:createdBy": "admin", "jcr:created": "Sun Feb 05 2023 16:50:26 GMT+0000", "sling:match": "$", "sling:internalRedirect": "/content/we-retail/us/en(\.html)?" }

 

Both the solution we actually tried but no luck with the regex patterns or the proper rewrite conditions as well. Could you please help me with the correct sling match or the rewrite condition if possible.

arunpatidar
New Participant
February 6, 2023

I would suggest to put this redirect at apache as mentioned by @albinis1 

 

For sling mappings, you can check the below documents 

https://sling.apache.org/documentation/the-sling-engine/mappings-for-resource-resolution.html 

Arun Patidar