From 9dca5a5f64404254d88cd8fd2cd83bd50d7f13cd Mon Sep 17 00:00:00 2001 From: Hans Nieser Date: Mon, 19 Jan 2026 11:14:49 +0100 Subject: [PATCH] fix(magento-store): redirect product URLs without /p/ prefix to product route When visiting a product URL without the configured product route prefix (e.g., /my-product instead of /p/my-product), the redirectOrNotFound function would return a 404 even though Magento's route resolver successfully identified it as a product. The issue occurs when relative_url equals the incoming URL - no redirect was triggered because the code only redirected when relative_url !== from. However, for products accessed without the /p/ prefix, we still need to redirect to the product route even when the URL key matches. This fix adds a check: if the route resolver finds a product but there's no explicit redirect URL (relative_url === from), redirect to the product route anyway. --- packages/magento-store/utils/redirectOrNotFound.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/magento-store/utils/redirectOrNotFound.ts b/packages/magento-store/utils/redirectOrNotFound.ts index cdc29ecf8b..c7d1ae35f7 100644 --- a/packages/magento-store/utils/redirectOrNotFound.ts +++ b/packages/magento-store/utils/redirectOrNotFound.ts @@ -136,6 +136,12 @@ export async function redirectOrNotFound( : redirect(from, `/${redirectUrl}`, permanent, locale) } + // If no explicit redirect but route is a product, redirect to product route + if (routeData.route?.relative_url && isTypename(routeData.route, productInterfaceTypes)) { + const productPath = `${productRoute ?? '/p/'}${routeData.route.relative_url}` + return redirect(from, productPath, permanent, locale) + } + return notFound(from, 'Route found, but no redirect URL') } catch (e) { if (e instanceof Error) {