Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session

Using Dispatcher code in AEM SPA cloud shortening the URL

Avatar

Level 7

I have written Dispatcher rewrite to shorten the URL. Urls are being shortened but the page is not rendering anything it is appearing blank.

Model JSON is loading fine on both Publish and Dispatcher content is exactly the same. Screenshot is attached below

 

On Publish env

Ronnie09_0-1684937775902.png


On Dispatcher

Ronnie09_2-1684937838460.png

 

What shall I do now? I am confused

14 Replies

Avatar

Community Advisor

it seems you clientlibs are not loading, can you check is proxy enabled for the required clientlibs or not?

Avatar

Level 7

@Umesh_Thakur 

 

Clientlibs are loading that icon is coming because of HTTP request. I tried to open in new tab it has the data

Avatar

Community Advisor

Can you check https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/aem-spa-react-dispatcher-s... for dispatcher setup with AEM SPA project.

Also, check AEM and dispatcher logs to see any error.

Avatar

Level 7

Hi @rawvarun 

 

Yes, I check that solution out. My model json and the path are the same as well as there are no errors on the Dispatcher log.

 

For frontend changes,  I followed https://experiencing150.rssing.com/chan-25971229/article453.html 

Avatar

Community Advisor

I don’t see .html file extension fir the dispatcher url. Can you check with .html extension for dispatcher url as well or you have setup on dispatcher to work as extension less url?

Avatar

Community Advisor

So when you request page from dispatcher does the request going to aem publisher and if not then you might need to check the dispatcher rules for shortened url

Avatar

Level 7

@DPrakashRaj 

How can I verify that?
My Dispatcher code

<IfModule mod_rewrite.c>
RewriteEngine on
 
    # rewrite for load root page
    RewriteCond %{HTTP_HOST} !^localhost    
    RewriteRule ^/?$ http://%{ENV:SAMPLE_HOST_PREFIX}%{HTTP_HOST}/us/en/home.html [R=301,L]
 
   
    # rewrite for redirect wrong links that beginning with '/content/sample'
    RewriteRule ^/content/sample/(.*) /$1 [E=SAMPLE_REDIRECT:1,NC]
 
    # rewrite for redirect wrong links that ending with extension '.html'
    RewriteCond %{HTTP_HOST} !^localhost    
    RewriteCond %{REQUEST_URI} !^/libs
    RewriteRule ^(.*)\.html$ $1 [E=SAMPLE_REDIRECT:1,N,NC]
 
    # rewrite for redirect wrong links that ending with '/'
    RewriteCond %{HTTP_HOST} !^localhost    
    RewriteRule ^(.*)/$ $1 [E=SAMPLE_REDIRECT:1,N]
 
    RewriteCond  %{ENV:SAMPLE_REDIRECT} "=1" [OR]
    #RewriteCond  %{ENV:SAMPLE_HOST_PREFIX} "=www." [OR]
    RewriteCond  %{ENV:SAMPLE_HTTPS} "=1"
    RewriteCond  %{REQUEST_URI} !^/dispatcher/invalidate.cache$
    RewriteRule ^(.*)$ http://%{ENV:SAMPLE_HOST_PREFIX}%{HTTP_HOST}$1 [R=301,L]
 
    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} \.(jpe?g|png|svg|json|form)$
    RewriteRule ^/(.*)$ /content/sample/$1 [PT,L]
 
    RewriteCond %{REQUEST_URI} !^/content/ [NC]
    RewriteCond %{REQUEST_URI} !^/etc.clientlibs [NC]
    RewriteCond %{REQUEST_URI} !^/bin [NC]
    RewriteCond %{REQUEST_URI} !^/libs
    RewriteCond %{REQUEST_URI} !\.(.+)$
    RewriteRule ^/([^\?]*)(.*)$ /content/sample/$1.html$2 [PT,L]
</IfModule>

Avatar

Community Advisor

Check request.log and access.log of aem publisher

Avatar

Level 7

@DPrakashRaj 

Request and access log are empty of publish, whenever I request 4503 then only it is printing someting. On hitting dispatcher url no log is printed on request.log and access.log

Avatar

Community Advisor

That means your dispatcher is not configured correctly. You need to debug on the dispatcher by setting the dispatcher log as debug and check what happens with the request 

Avatar

Level 2

Is the request going as full path to publisher from dispatcher after you rewrite in dispatcher?. It seems publisher could not process shorten url. We can enable shorten url using JcrResourceResolverFactoryImpl. Please check the below article.

 

https://blogs.perficient.com/2021/01/11/unit-testing-jcr-resource-resolver-mappings/

 

Avatar

Level 7

@purnatummalapalli 

How can I verify that request is going to publish. Currently, I just have a dispatcher which is handling everything.

 

<IfModule mod_rewrite.c>
RewriteEngine on
 
    # rewrite for load root page
    RewriteCond %{HTTP_HOST} !^localhost    
    RewriteRule ^/?$ http://%{ENV:SAMPLE_HOST_PREFIX}%{HTTP_HOST}/us/en/home.html [R=301,L]
 
   
    # rewrite for redirect wrong links that beginning with '/content/sample'
    RewriteRule ^/content/sample/(.*) /$1 [E=SAMPLE_REDIRECT:1,NC]
 
    # rewrite for redirect wrong links that ending with extension '.html'
    RewriteCond %{HTTP_HOST} !^localhost    
    RewriteCond %{REQUEST_URI} !^/libs
    RewriteRule ^(.*)\.html$ $1 [E=SAMPLE_REDIRECT:1,N,NC]
 
    # rewrite for redirect wrong links that ending with '/'
    RewriteCond %{HTTP_HOST} !^localhost    
    RewriteRule ^(.*)/$ $1 [E=SAMPLE_REDIRECT:1,N]
 
    RewriteCond  %{ENV:SAMPLE_REDIRECT} "=1" [OR]
    #RewriteCond  %{ENV:SAMPLE_HOST_PREFIX} "=www." [OR]
    RewriteCond  %{ENV:SAMPLE_HTTPS} "=1"
    RewriteCond  %{REQUEST_URI} !^/dispatcher/invalidate.cache$
    RewriteRule ^(.*)$ http://%{ENV:SAMPLE_HOST_PREFIX}%{HTTP_HOST}$1 [R=301,L]
 
    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} \.(jpe?g|png|svg|json|form)$
    RewriteRule ^/(.*)$ /content/sample/$1 [PT,L]
 
    RewriteCond %{REQUEST_URI} !^/content/ [NC]
    RewriteCond %{REQUEST_URI} !^/etc.clientlibs [NC]
    RewriteCond %{REQUEST_URI} !^/bin [NC]
    RewriteCond %{REQUEST_URI} !^/libs
    RewriteCond %{REQUEST_URI} !\.(.+)$
    #/ar-us
    RewriteRule ^/([^\?]*)(.*)$ /content/sample/$1.html$2 [PT,L]
</IfModule>

Avatar

Level 2

we are also facing similar issue. Was there any solution for this?