One of the key aspects of optimizing your Adobe Experience Manager (AEM) implementation is effective caching, particularly through the AEM Dispatcher. However, not all URLs are created equal when it comes to caching. In this article, we will explore why URLs without extensions are not cached, the restrictions involved, and how to use Apache rules as a fallback with the [PT] (Pass Through) flag.
1. URLs Without Extensions Are Not Cached
In AEM, URLs must always have an extension to be cacheable by the Dispatcher. While you can serve URLs without extensions in AEM, these URLs will not be cached by the Dispatcher, leading to potential performance issues.
2. Examples
Cacheable URL:
1 | http://domain.com/home.html |
This URL includes an extension (.html) and is therefore cacheable by the Dispatcher.
Non-cacheable URL:
1 | http://domain.com/home |
This URL lacks an extension and will not be cached by the Dispatcher. However, if you use the [PT] pass through to internal AEM resource ending with .html, it will be cached.
3. Using Apache [PT] Pass Through as a Fallback
To handle URLs without extensions and ensure they are still processed correctly, you can use Apache’s [PT] (Pass Through) flag. This allows the URL to be passed through to the backend server, appending .html to the request, thereby enabling it to be cached by the Dispatcher.
Example Apache Configuration
Consider the following common dispatcher configuration to handle extensionless URLs:
1 2 3 4 5 6 7 8 9 10 11 12 13 | RewriteEngine On 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] |
With this configuration, when a domain like http://domain.com/en/home is hit, it will actually map to:
1 | /content/${CONTENT_FOLDER_NAME}/en/home.html |
For example, if ${CONTENT_FOLDER_NAME} is wknd, the URL http://domain.com/en/home would map to:
1 | /content/wknd/en/home.html |
This allows the Dispatcher to cache the resource correctly.
4. Additional Examples
Original URL:
1 | http://domain.com/en/home |
Rewritten URL with [PT]:
1 | /content/wknd/en/home.html |
Original URL:
1 | http://domain.com/about |
Rewritten URL with [PT]:
1 | /content/wknd/about.html |
In both examples, the extensionless URLs are mapped to URLs ending in .html, making them cacheable by the Dispatcher.
5. Conclusion
To ensure your pages are cached by the Dispatcher, always add extensions to your URLs. Some may argue that having extensions in URLs could negatively affect SEO rankings. However, an uncached page can lead to slow loading times, which can hurt your SEO rankings even more.
By following these guidelines and using Apache [PT] rules as a fallback, you can optimize your AEM Dispatcher caching strategy and improve the performance and reliability of your AEM instance.