Skip to content

Commit fad1e2d

Browse files
committed
Attempt to avoid redirects when an asset isn't found
1 parent b52802b commit fad1e2d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

next.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ const i18nConfig = require('./src/i18nConfig');
55
const supportedLocales = i18nConfig.supportedLocales.map((supportedLocale) => {
66
return supportedLocale.name;
77
});
8+
const publicBasePaths = ['robots', 'static', 'favicon.ico']; // All items (folders, files) under /public directory should be added there, to avoid redirection when an asset isn't found
9+
const noRedirectBasePaths = [...supportedLocales, ...publicBasePaths]; // Will disable url rewrite for those items (should contain all supported languages and all public base paths)
810

911
console.debug(`Building Next with NODE_ENV="${process.env.NODE_ENV}" APP_STAGE="${process.env.APP_STAGE}" for CUSTOMER_REF="${process.env.CUSTOMER_REF}"`);
1012

@@ -61,7 +63,7 @@ module.exports = withSourceMaps({
6163
destination: '/api/autoRedirectToLocalisedPage',
6264
},
6365
{
64-
source: `/:locale((?!${supportedLocales.join('|')})[^/]+)(.*)`,
66+
source: `/:locale((?!${noRedirectBasePaths.join('|')})[^/]+)(.*)`,
6567
destination: '/api/autoRedirectToLocalisedPage',
6668
},
6769
];

0 commit comments

Comments
 (0)