Expand my Community achievements bar.

SOLVED

Image V3 Component with Resource Mapping

Avatar

Level 1

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. 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

View solution in original post

5 Replies

Avatar

Community Advisor

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

Avatar

Level 1

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.

Avatar

Community Advisor

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

 

For sling mappings, you can check the below documents 

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



Arun Patidar

Avatar

Correct answer by
Community Advisor

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

Avatar

Level 2

Hi @Albin_Issac ,

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]