Hello, currently I have a servlet that sends to call an api that brings a JSON, this JSON are products and can be X amount, in order once called these products I save them in content fragments.
And the next part is that I have a dynamic component, the component doesn't show information until by means of the url you indicate him that product you want to visualize to achieve this you have the following link
domain.com/products
you will have to indicate in the url that product you want to visualize with a selector of the following way:
domain.com/products.product1
the variable product1 is a variable named product_title and is the content fragment product id, and this way the component will go to look for in the content fragment of the jcr that product and will show the information. It works everything and perfect, but now what I want to do is that instead of using
domain.com/products.product1
use now
domain.com/products/product1
That is to say to use a / instead of .
The problem is that if I use a / AEM detects me as if looking for a page created and existing in the path after products, which is not so, what can I do to add that rule or modification?
This is my component model code:
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
Hi @Aaron_Dempwolff
The rewrite rule shared as sample. you need to write your own based on content taxonomy.
For example if Product path are at
/content/tfs/us/en/test-folder/products/T.html
then
#Example product redirect
^/content/tfs/([a-zA-Z]{2})/([a-zA-Z]{2})/test-folder/products/(.*) /content/tfs/$1/$2/test-folder/products.$3 [PT,L]
One approach would be that you can try using dispatcher rule to rewrite the URL's
as example.com/abc/xyz.html to example.com/abc.xyz.html
RewriteRule ^([^/]+)/([^/]+)\.html$ /$1.$2.html [L]
(Add the appropriate rewrite condition for this rule)
Yes, Use rewrite rule. No need to change any backend logic
#product redirect
RewriteRule ^/products/(.*) /product.$1 [PT,L]
From what I understand, modifying the rewrite.rules or dispatcher will only redirect the page so that if the user types
domain/products/product1
the url will be redirected or disguised.
domain/products.product1
but that does'nt make the model work, since it is designed to use a selector (.)
I have tried with the rule that you told me and I get the same error, it tries to access a page that already exists or is in AEM, which is not the case.
If I use the selector (.) it works
But If I use the slash (/) even with the rewrite rule it still doesn't work
I got the next error:
Cannot serve request to /content/tfs/us/en/test-folder/products/T.html in BundledScriptServlet (/libs/sling/servlet/errorhandler/404.jsp)
Hi @Aaron_Dempwolff
The rewrite rule shared as sample. you need to write your own based on content taxonomy.
For example if Product path are at
/content/tfs/us/en/test-folder/products/T.html
then
#Example product redirect
^/content/tfs/([a-zA-Z]{2})/([a-zA-Z]{2})/test-folder/products/(.*) /content/tfs/$1/$2/test-folder/products.$3 [PT,L]
I think as @AMANATH_ULLAH highlighted, using Dispatcher Rewrite rules, you can achieve above use case but only on dispatcher.
If you want it to work internally in AEM and other environments , the best solution would be to use sling mapping
http://[host]:[port]/system/console/configMgr/org.apache.sling.jcr.resource.internal.JcrResourceReso...
In above configuration under URL Mappings you can create a mapping that routes requests like domain.com/products/product1 to the path.
You can take help of this blog : https://abhigyanswaroop.medium.com/resource-mapping-in-adobe-experience-manager-aem-1658653a683
to change mapping of resource.resolver.mapping value in above configuration.
I am already using the same feature in my current project. You need to use rewrite rules only.
RewriteRule ^/products/([A-Za-z0-9\-_]+)$ /content/siteName/us/en/products.$1.html [NC,PT,L]
@Aaron_Dempwolff Did you find the suggestions helpful? Please let us know if you require more information. Otherwise, please mark the answer as correct for posterity. If you've discovered a solution yourself, we would appreciate it if you could share it with the community. Thank you!
Views
Replies
Total Likes
Views
Likes
Replies