Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

Rewrite rules causing model.json to be requested twice

Avatar

Level 2

Hi,

 

We are setting up a new project, where the developers are making use of the AEM JSON exporter to create a file with the name "pagename.model.json" for an incoming request, which is then used by the Angular code on the browser to render the webpage. 

 

I have added a rewrite rule to mask the path "/content/<project-name>" in the URL with the following rule.

 

RewriteRule ^/(.*) /content/<project-name>/$1 [PT]

 

The rewrite is working as expected for the HTML pages, however, the model.json files are being called twice once without the "/content/<project-name>" and once with it, which is causing a couple of issues in the page rendering.

 

Is there any way to eliminate the call with the content path?

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

7 Replies

Avatar

Level 4

Hi @ashish_kamalaksha,

 

Unfortunately, we need more details about all other rewrite rules. I would suggest to investigate rewrite rules locally by increasing rewrite log level in the apache configuration.

If you are running on AEMaaCS, you can define REWRITE_LOG_LEVEL variable:

REWRITE_LOG_LEVEL=trace6

If you are running on custom Apache server add this line to the vhost configuration (https://httpd.apache.org/docs/2.4/mod/mod_rewrite.html

LogLevel alert rewrite:trace6

HI @konstantyn_diachenko 

 

We currently only have 2 redirection rules in place. 

1. RewriteRule ^/$ /content/<project-name>/home.html [PT,L] ( To redirect / to the home page internally )
2. 

RewriteCond %{REQUEST_URI} !^/apps/(.*) [NC]
RewriteCond %{REQUEST_URI} !^/bin/(.*) [NC]
RewriteCond %{REQUEST_URI} !^/etc(.*) [NC]
RewriteCond %{REQUEST_URI} !^/libs(.*) [NC]

RewriteCond %{REQUEST_URI} !^/content(.*) [NC]
RewriteCond %{REQUEST_URI} !^/system(.*) [NC]
RewriteCond %{REQUEST_URI} !^/dam(.*) [NC]
RewriteCond %{REQUEST_URI} !^/server-status [NC]
RewriteCond %{REQUEST_URI} !^/dispatcher/invalidate.cache [NC]
RewriteCond %{REQUEST_URI} !^/$

RewriteRule ^/(.*) /content/<project-name>/home/$1 [PT,L] (To mask /content/<project-name>/ in all requests that are under this path)

 

I have enabled the higher log level for rewrite, and also checked access logs. It seems the first request is for model.json with the content path and then for the one without. 

 

For example for the path "/", it is successfully redirecting internally to the expected homepage. Then a request for /content/<project-name>/home.html is received followed shortly by a request for /.model.json.

Try to add explicit following rules between 1st and 2nd rule for testing:

RewriteRule ^(.*).model.json /content/<project-name>/home$1.model.json [PT,L]
RewriteRule ^/.model.json /content/<project-name>/home.model.json [PT,L]

 

I see that you 2nd rule starts with /.

In this case case the path /child-page.html will be rewritten to go further to AEM with /content/<project-name>/home/child-page.html. A /child-page.model.json ->  /content/<project-name>/home/child-page.model.html.

But if you open home page (just /), your code will send /.model.json request and it will be rewritten to /content/<project-name>/home/.model.html that is wrong. Try to test dispatcher with 2 explicit rules above.

 

Hope it helps.

 

 

HI @konstantyn_diachenko,

 

If I am not wrong, this rule "RewriteRule ^/(.*) /content/<project-name>/home/$1 [PT,L]" should also redirect any model.json pages to the right path. For example, /abc.model.json would be redirected to  /content/<project-name>/home/abc.model.json

 

I have added the rule to redirect /.model.json to  /content/<project-name>/home.model.json.

 

However, this does not eliminate the dual calls being made from the browser (one with full content path and one without )

Avatar

Community Advisor

@ashish_kamalaksha as said by @konstantyn_diachenko we might need more details..

 

But few things to look for

More than one rewrite rule matching , for this use L apache flag which marks the rule as last rewrite and doesn't execute subsequent rules

 

Check if your publish farms are multiple and all are executed.

Avatar

Level 2

Hi @Shashi_Mulugu 

 

Currently, we only have a dev setup ( 1 each of author, publisher and dispatcher ) and only 2 redirect rules at the moment. 

 

1. RewriteRule ^/$ /content/<project-name>/home.html [PT,L] ( To redirect / to the home page internally )
2. 

RewriteCond %{REQUEST_URI} !^/apps/(.*) [NC]
RewriteCond %{REQUEST_URI} !^/bin/(.*) [NC]
RewriteCond %{REQUEST_URI} !^/etc(.*) [NC]
RewriteCond %{REQUEST_URI} !^/libs(.*) [NC]

RewriteCond %{REQUEST_URI} !^/content(.*) [NC]
RewriteCond %{REQUEST_URI} !^/system(.*) [NC]
RewriteCond %{REQUEST_URI} !^/dam(.*) [NC]
RewriteCond %{REQUEST_URI} !^/server-status [NC]
RewriteCond %{REQUEST_URI} !^/dispatcher/invalidate.cache [NC]
RewriteCond %{REQUEST_URI} !^/$

RewriteRule ^/(.*) /content/<project-name>/home/$1 [PT,L] (To mask /content/<project-name>/ in all requests that are under this path)

 

I have enabled the higher log level for rewrite, and also checked access logs. It seems the first request is for model.json with the content path and then for the one without. 

 

For example for the path "/", it is successfully redirecting internally to the expected homepage. Then a request for /content/<project-name>/home.html is received followed shortly by a request for /.model.json.

Avatar

Community Advisor

Got it, please not condition for model.json in your regular rules and create a new rule only for model.json