We currently have a problem with SSR optimized engine. The scenario is that a product has been removed or renamed on the catalog, and the user tends to access that old none existing URL directly. Then we have implemented a redirected behavior sending a status code of 301 so that the customer gets redirected to a relevant page where its URL is retrieved from BE. (Through a generic HTTP interceptor catchError)
catchError((error: any) => {
if (error instanceof HttpErrorResponse) {
...
this.response.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
this.response.set('location',this.service.urlBuilder(redirectUrl));
return this.setMovedPermanentlyStatus();
}
}
However, we also have those pages cached, so the next time that the page comes from the cache, it returns 200 instead of 301, which we tried to implement in the first place. We tried to rule out those with 301 not to be treated like others, but it still returns with 200 when they're coming from the cache. ( By extending SSR optimized engine with an exception like )
protected fallbackToCsr(response: Response, filePath: string, callback: SsrCallbackFn): void {
if (response.statusCode !== HttpResponseStatus.MOVED_PERMANENTLY) {
response.set('Cache-Control', 'no-store');
callback(undefined, this.getDocument(filePath));
}
}
We're looking for a solution to ensure that all 'the redirected pages' will always respond with 301 and not 200, even if they come from the cache.