So I am curious about this redirect @snorkypie when I break it down to me it would redirect every page that is not accounted for in our next.config.js to /blog/ but here is our next.config.js file:
const withPlugins = require(‘next-compose-plugins’);
const Contentful = require(‘./utils/contentful’);
const Slugify = require(‘slugify’);
const nextJsConfig = {
// fix for imported assets that require url loader
trailingSlash: true,
webpack: function (config) {
config.module.rules.push({
test: /.(eot|woff|woff2|ttf|svg|png|jpg|gif)$/,
use: {
loader: ‘url-loader’,
options: {
limit: 100000,
name: ‘[name].[ext]’
}
}
});
return config;
},
async exportPathMap() {
var pages = {
‘/’: { page: ‘/’ },
‘/pricing’: { page: ‘/pricing’ },
‘/employers’: { page: ‘/employers’ },
‘/brokers’: { page: ‘/brokers’ },
‘/courtesyof’: { page: ‘/courtesyof’ },
‘/fsa’: { page: ‘/fsa’ },
‘/update-browser’: { page: ‘/update-browser’ },
‘/marketplace’: { page: ‘/marketplace’ },
‘/about-us’: { page: ‘/about-us’ },
‘/careers’: { page: ‘/careers’ },
‘/partners’: { page: ‘/partners’ },
‘/blog’: { page: ‘/blog’ },
‘/blog/employer’: { page: ‘/blog/segment’ },
‘/blog/broker’: { page: ‘/blog/segment’ },
‘/blog/partner’: { page: ‘/blog/segment’ },
‘/blog/search’: { page: ‘/blog-search’ },
‘/affiliate-program’: { page: ‘/affiliate-program’ },
‘/resources’: { page: ‘/resources/segment’ },
‘/resources/individual’: { page: ‘/resources/segment’ },
‘/resources/employer’: { page: ‘/resources/segment’ },
‘/resources/partner’: { page: ‘/resources/segment’ },
‘/app’: { page: ‘/app’ },
‘/whats-eligible’: { page: ‘/eligibility’ },
‘/features’: { page: ‘/individual-benefits’ },
‘/employers/features’: { page: ‘/employer-features’ },
‘/hsa-savings-calculator’: {
page: ‘/hsa-savings-calculator’
},
‘/hsa-contribution-calculator’: {
page: ‘/hsa-contribution-calculator’
},
‘/hsa-savings-calculator/’: {
page: ‘/hsa-savings-calculator/’
},
'/compare-health-insurance-plans': {
page: '/calculator-compare-health-insurance-plans'
},
'/compare-health-insurance-plans/your-details': {
page: '/calculator-compare-health-insurance-plans-details'
},
'/compare-health-insurance-plans/plan': {
page: '/calculator-compare-health-insurance-plans-plan'
},
'/compare-health-insurance-plans/alternate-plan': {
page: '/calculator-compare-health-insurance-plans-alt-plan'
},
'/compare-health-insurance-plans/medical-expenses': {
page: '/calculator-compare-health-insurance-plans-medical-expenses'
},
'/compare-health-insurance-plans/results': {
page: '/calculator-compare-health-insurance-plans-results'
},
'/payroll-tax-savings': {
page: '/calculator-payroll-tax-savings'
},
'/payroll-tax-savings/cost-and-contributions': {
page: '/calculator-payroll-tax-savings-cost'
},
'/payroll-tax-savings/results': {
page: '/calculator-payroll-tax-savings-results'
},
'/hsa-contribution-calculator': {
page: '/hsa-contribution-calculator'
},
'/404': { page: '/_error' }
};
//Blog Posts
let blogPosts = await Contentful.query(
{
content_type: 'blogPost',
limit: 1000
},
'misc'
);
for (let i in blogPosts.items) {
if (blogPosts.items[i].fields.slug) {
if (
typeof blogPosts.items[i].fields.segmentId !== 'undefined' &&
blogPosts.items[i].fields.segmentId !== 'individual'
) {
Object.assign(pages, {
[`/blog/${blogPosts.items[i].fields.segmentId}/${blogPosts.items[i].fields.slug}`]: {
page: '/blog/article'
}
});
} else {
Object.assign(pages, {
[`/${blogPosts.items[i].fields.slug}`]: {
page: '/blog/article'
}
});
}
}
}
// Blog Categories
var blogCategories = await Contentful.query(
{ content_type: 'blogCategory', limit: 1000 },
'misc'
);
for (const i in blogCategories.items) {
if (blogCategories.items[i].fields.slug) {
Object.assign(pages, {
[`/category/${Slugify(blogCategories.items[i].fields.slug)}`]: {
page: '/category'
}
});
}
}
//Blog Tags
var blogTags = await Contentful.query({ content_type: 'blogTag', limit: 1000 }, 'misc');
for (const i in blogTags.items) {
if (blogTags.items[i].fields.slug) {
Object.assign(pages, {
[`/tag/${Slugify(blogTags.items[i].fields.slug)}`]: {
page: '/tag'
}
});
}
}
//Blog Persona Tags
var blogPersonaTags = await Contentful.query(
{
content_type: 'blogPersonaTag',
limit: 1000
},
'misc'
);
for (const i in blogPersonaTags.items) {
if (blogPersonaTags.items[i].fields.slug) {
Object.assign(pages, {
[`/tag/${Slugify(blogPersonaTags.items[i].fields.slug)}`]: {
page: '/persona-tag'
}
});
}
}
//Feature Templates
var featurePages = await Contentful.query({
content_type: 'pageFeatureTemplate',
limit: 1000
});
for (const i in featurePages.items) {
if (featurePages.items[i].fields.slug)
Object.assign(pages, {
[`${featurePages.items[i].fields.slug}`]: {
page: '/feature'
}
});
}
//Basic Templates
var basicTemplates = await Contentful.query({
content_type: 'pageSimpleTemplate',
limit: 1000
});
for (const i in basicTemplates.items) {
if (basicTemplates.items[i].fields.slug)
Object.assign(pages, {
[`${basicTemplates.items[i].fields.slug}`]: {
page: '/basic-template'
}
});
}
//Small Business Templates
var smallBusinessTemplates = await Contentful.query(
{
content_type: 'pageSmallBusinessTemplate',
limit: 1000
},
'misc'
);
for (const i in smallBusinessTemplates.items) {
if (smallBusinessTemplates.items[i].fields.slug)
Object.assign(pages, {
[`${smallBusinessTemplates.items[i].fields.slug}`]: {
page: '/small-business-template/small-business-template'
}
});
}
//Guide Templates
var guideTemplates = await Contentful.query(
{
content_type: 'pageGuideTemplate',
limit: 1000
},
'misc'
);
for (const i in guideTemplates.items) {
if (guideTemplates.items[i].fields.slug)
Object.assign(pages, {
[`${guideTemplates.items[i].fields.slug}`]: {
page: '/guide-template/guide-template'
}
});
}
//Content Download Templates
var downloadTemplates = await Contentful.query(
{
content_type: 'pageContentDownloadTemplate',
limit: 1000
},
'misc'
);
for (const i in downloadTemplates.items) {
if (downloadTemplates.items[i].fields.slug)
Object.assign(pages, {
[`${downloadTemplates.items[i].fields.slug}`]: {
page: '/content-download-template'
}
});
}
//Confirmation Templates
var confirmationTemplates = await Contentful.query(
{
content_type: 'pageConfirmationTemplate',
limit: 1000
},
'misc'
);
for (const i in confirmationTemplates.items) {
if (confirmationTemplates.items[i].fields.slug)
Object.assign(pages, {
[`${confirmationTemplates.items[i].fields.slug}`]: {
page: '/confirmation'
}
});
}
//Why You need Templates
var whyTemplates = await Contentful.query({
content_type: 'pageWhyYouNeedHsa',
limit: 1000
});
for (const i in whyTemplates.items) {
if (whyTemplates.items[i].fields.slug)
Object.assign(pages, {
[`${whyTemplates.items[i].fields.slug}`]: {
page: '/why-you-need-an-hsa'
}
});
}
//Careers
var careers = await Contentful.query({
content_type: 'pageCareer',
limit: 1000
});
for (const i in careers.items) {
if (careers.items[i].fields.url)
Object.assign(pages, {
[`${careers.items[i].fields.url}`]: {
page: '/career'
}
});
}
//Careers
var security = await Contentful.query({
content_type: 'pageSecurityTemplate',
limit: 1000
});
for (const i in security.items) {
if (security.items[i].fields.slug)
Object.assign(pages, {
[`${security.items[i].fields.slug}`]: {
page: '/security-template'
}
});
}
//partners
var partners = await Contentful.query({
content_type: 'pagePartnerTemplate',
limit: 1000
});
for (const i in partners.items) {
if (partners.items[i].fields.slug)
if (partners.items[i].fields.slug.indexOf('?') >= 0) {
Object.assign(pages, {
[`${partners.items[i].fields.slug.split('?')[0]}`]: {
page: '/partner-template'
}
});
} else {
Object.assign(pages, {
[`${partners.items[i].fields.slug}`]: {
page: '/partner-template'
}
});
}
}
//authors
var authors = await Contentful.query(
{
content_type: 'author',
limit: 1000
},
'misc'
);
for (const i in authors.items) {
if (authors.items[i] && authors.items[i].fields.name) {
const url = Slugify(authors.items[i].fields.name);
if (url) {
Object.assign(pages, {
[`/author/${url}`]: {
page: '/blog/author'
}
});
}
}
}
return pages;
}
};
module.exports = withPlugins(, nextJsConfig);
In practice this does not work. One case is the 404 which I mentioned plus pages that are in this file like:
https://livelyme.com/calculator-compare-health-insurance-plans-alt-plan is redirecting to https://livelyme.com/blog/calculator-compare-health-insurance-plans-alt-plan
The nextconfig states: ‘/compare-health-insurance-plans/alternate-plan’: {
page: ‘/calculator-compare-health-insurance-plans-alt-plan’
This: https://livelyme.com/calculator-compare-health-insuran ce-plans-medical-expenses/ https://livelyme.com/blog/calculator-compare-health-insur ance-plans-medical-expenses/
nextconfig: ‘/employers/features’: { page: ‘/employer-features’ }, works:
But this redirects to blog: https://livelyme.com/employer-features/invest/
https://livelyme.com/blog/employer-features/invest/
AND is not in the nextconfig file (is that the problem here? Do all pages need to be identified in nextconfig.js?
This is a pretty hairy animal. I appreciate any help I can get here - thanks @luke