Tuesday, April 24, 2018

How to handle the request parameter encoding(charset) in Adobe Experience Manager(AEM)

How to handle the request parameter encoding(charset) in Adobe Experience Manager(AEM)


The default value for the parameter encoding in AEM is UTF8 — The default request parameter encoding used to decode request parameters into strings.

The configured parameter encoding value e.g UTF8 is used to decode the request parameters to string.

Sometimes we may need to change the default parameter encoding in Adobe Experience Manager(AEM) to handle different language characters.

This tutorial explains the approach to change the default parameter encoding to required values e.g UTF8, ISO-8859–1 etc

The request parameter can be changed by following either one of the below approach
  • Apache Sling Request Parameter Handling
  • Change the encoding for specific form

Apache Sling Request Parameter Handling


The request parameter encoding can be changed through the following OSGI configuration — “Apache Sling Request Parameter Handling”. This is the global configurations and impact all the request parameter handling(decoding)

“Default Parameter Encoding” — The default request parameter encoding used to decode request parameters into strings. If this property is not set the default encoding is ‘ISO-8859–1’ as mandated by the Servlet API spec. This default encoding is used if the ‘_charset_’ request parameter is not set to another (supported) character encoding. Applications being sure to always use the same encoding (e.g. UTF-8) can set this default here and may omit the ‘_charset_’ request parameter (sling.default.parameter.encoding)

The AEM server configures UTF-8 as the default parameter, ‘ISO-8859–1’ is considered as default encoding if this field is empty.



Change the value of “Default Parameter Encoding” to required values — e.g UTF-8/ISO-8859–1

Change the encoding for specific form


The request parameter can be changed to specific form by following the below steps

Add the parameter “_charset_” as a hidden field with required encoding value inside the form.

<form role=”form” id=”test” action=”xxxxx” method=”POST” accept-charset=”ISO-8859–1" onsubmit=”document.charset = ‘ISO-8859–1’”>
<input type=”hidden” id=”_charset_” name=”_charset_” value=”ISO-8859–1"/>
……..
……..
</form>

accept-charset=”ISO-8859–1" — specifies the character encoding that to be used for the form submission(non IE browsers)

“document.charset = ‘ISO-8859–1’” — specifies the character encoding that to be used for the form submission(Configuration for IE browser)

This will change the encoding of this particular form, different encoding can be specified page level and form level only to handle the data.


Wednesday, April 18, 2018

How to implement extension-less URL's in Adobe Experience Manager(AEM)

How to implement extension-less URL's in Adobe Experience Manager(AEM)

As per the SEO best practices it is better to define extension less URL's to boost the ranking, AEM require the extension to understand and serve incoming request.

This post explains the approach to achieve the extension less URL in Adobe Experience Manager(AEM)

There are two steps

- Rule Configuration Dispatcher
       Remove .html extension from incoming URL with /
Append the .html while invoking the publisher for the URL's ending with /

- AEM etc/map configuration
      Reverse mapping to rewrite the html URL in the pages to extension less
      Forward mapping to map the incoming request to resource

This is tested in AEM 6.2 version

Apache configurations:


#Handle the landing page
RewriteRule ^/$ /en/ [R=301,L]
#Mask the /content/geometrixx-outdoors path
RewriteRule ^/content/geometrixx-outdoors/(.*)(\.html)?$ /$1 [NE,L,R=301]

#Replace the .html with /
RewriteCond %{REQUEST_URI} \.html$
RewriteRule ^/(.*).html$ /$1/ [R=301,L,QSA]

#Append the .html for those URL's ending with / before sending to publisher
RewriteCond %{REQUEST_URI} !^/$
RewriteRule ^/(.*)/$ /$1.html [PT,L,QSA]

Publisher etc/map configurations:


Create a node localhost.8080(replace with required DNS and port) of type sling:Mapping under /etc/map/http or /etc/map/https based on the protocol used

Add the following property

sling:internalRedirect[] - /content/geometrixx-outdoors

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
    jcr:primaryType="sling:Mapping"
    sling:internalRedirect="[/content/geometrixx-outdoors]">
    <redirect/>
    <reverse/>
</jcr:root>

AEM-extension-less-URL




Sunday, April 1, 2018

Different approaches to perform Vanity/Redirect URL management in Adobe Experience Manager(AEM)

Different approach to perform Vanity/Redirect URL management in Adobe Experience Manager(AEM)

In Adobe Experience Manager there is no centralized management UI to manage the Vanity/Redirect URL's also the vanity/Redirects are added into multiple places like Apache and AEM.

This post will explain the different approach to manage the Vanity/Redirect URL through centralized management UI.

Option1: Manage the Vanity URL's through VanityPath page property

  • Build a UI application to read vanityPath properties from the repository content nodes and enable management options - Add, Delete, Modification
  • Refer the following URL for details on this approach - https://helpx.adobe.com/experience-manager/using/vanitypath.html(only working in 6.1)
  • Whitelist vanity paths in dispatcher - https://helpx.adobe.com/experience-manager/dispatcher/using/dispatcher-configuration.html#EnablingAccesstoVanityURLsvanityurls
The same approach can be followed to manage the redirect path enabled in AEM

Vanity URL's are handled in AEM so all the request reaches AEM publisher

Option2 - Manage the Vanity/redirects through AEM UI on XML and redirect through Java Filter


VanityURL_Redirect_Java_Filter


Store the vanity and redirects mapping in a XML file with in AEM repository

<rules>
<rule>
<siteName></siteName>
<code></code>
<sourcePath></sourcePath>
<target></target>

</rule>
<rules>

  • Build a UI application to manage the redirects in the file - modify/remove and add new rules
  • Replicate the mapping XML to publisher on every modification through replication API
  • Build a Java filter that will redirect to the target URL if the vanity path is defined in the XML file(the filter should be restricted only required path)
  • Whitelist the vanitypaths in Apache – Expose the vanitypaths through custom URL(Servlet expose the list of vanity URLs by parsing the XML) and configure the URL in Apache for whitelisting(Refer https://helpx.adobe.com/experience-manager/dispatcher/using/dispatcher-configuration.html#EnablingAccesstoVanityURLsvanityurls for apache configuration, the vanity list URL should be custom)

Vanity/Redirects are handled in AEM so all the request reaches AEM publisher