Is there a way to handle (receive in the middleware for example) 301/302 status code from Sitecore server returned to next.js as a response for Layout service call?

I used to use custom Node based implementation of Headless, where 301 from Sitecore was returned to the browser. In the sample application of next.js it seems to be 301 is performed by next.js server, not returned to the browser.

My IIS log proves it. The first request returns 301, I used to have it received by the browser, but at the moment as per the the following entries it seems to be next.js handles it. Is there a way to 'process' it by some custom middleware of something customized? At the moment I am able to track only final 404 in next.js server.

2024-04-23 14:15:53 GET /sitecore/api/layout/render/jss item=%2F**arrange**&sc_apikey=%7B3CA%7D&sc_site=C&sc_lang=en-gb&tracking=true 8280 - a/2- **301** 0 0 188058

2024-04-23 14:15:53 GET /**arrange2** tracking=true 8280 - a/2- **302** 0 0 164

2024-04-23 23:59:59 GET /sitecore/service/**notfound.aspx** item=%2f**arrange2**&user=extranet%5cAnonymous&site=website 8280 - Mozilla/5.0+..... http://localhost:3000/arrange **404** 0 0 6

1 Answer 1


I haven't really given this a try, but I found that Sitecore has an example of this implemented in the XM Cloud example repo as a middleware plugin.

Please check if this could be useful.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.