April 28, 2020
Estimated Post Reading Time ~

Rewrite Rules with PT(Pass Through) Flag is not working in AEM Dispatchers

HOW TO DEFINE SEO/USER-FRIENDLY URL'S IN ADOBE EXPERIENCE MANAGER(AEM)
The Rewrite Rules with PT Flag helps us to define the SEO/User-friendly URLs by hiding the internal URL's.

Let consider a scenario - The product URL should be rewritten to SEO/User-friendly URL.

The internal product URL is - /en/test/pdp/book.html?id=123, this URL is not SEO/User friendly as the title of the product is not part of the URL

The URL should be rewritten to /en/test/Sample_Book/book/pdp.html?id=123 internally without changing the browser URL



Dispatcher Changes:
Add the below Rewrite Rule in dispatcher virtual host

RewriteCond %{QUERY_STRING} ^id=(.*) [NC]
RewriteRule ^/en/test/(.*)/(.*)/pdp.html$ /en/test/pdp/$2.html?id=%1 [PT,L]

The new URL's - /en/test/Sample_Book/book/pdp.html?id=123 were returning 404 response after enabling the rewrite rules, based on the analysis Dispatcher sending the request to AEM(Adobe Experience Manager) with browser specific URL and not not the internal URL configured in the rewrite rule.

The Publisher was displaying the following error

GET /en/test/Sample_Book/book/pdp.html HTTP/1.1] org.apache.sling.engine.impl.SlingRequestProcessorImpl service: Resource /content/en/test/Sample_Book/book/pdp.html not found

To fix the issue, set DispatcherUseProcessedURL to 1 in httpd.conf file - This tells Dispatcher to use the pre-processed URL

PT flag in the rewrite rule allows Apache to pass the rewritten URL to Adobe Experience Manager(AEM) dispatcher


By aem4beginner

1 comment:

  1. I don't see any such variable or constant in httpd.conf file in AEM dispatcher. Can you help how to do internal redirect without modifying URL for end user?

    ReplyDelete

If you have any doubts or questions, please let us know.