Reputation: 25
Im trying to redirect pages with trailing slashes to no trailing slashes using nuxt redirect module. I’ve got nuxt configured for no trailing slashes so now need to do some redirects from old setup. Having an issue with child pages matching parent redirect rule.
nuxt redirect module - https://github.com/nuxt-community/redirect-module
Heres what a want to achieve:
/page-1/ - >/page-1
/page-1/child/ - > /page-1/child
I have this in my nuxt-redirect module settings:
redirect: [
{ from: '/page-1/', to: '/page-1' },
{ from: '/page-1/child/', to: '/page-1/child' }
]
But as a result I get this
/page-1 - correct redirect
/page-1child - incorrect (slash missing between page-1 and child as it matches the rule)
Can someone help me out with setting correct rules, not sure where to look. Or an alternative method that will make it work.
Thanks!
Upvotes: 0
Views: 1686
Reputation: 25
Think I found a solution. Should be using regex as exact match:
redirect: [
{ from: '^\/page-1\/$', to: '\/page-1', statusCode: 301 },
{ from: '^\/page-1\/child\/$', to: '\/page-1\/child', statusCode: 301 }
]
Not sure if its the best way to do it, but it solved my problem.
Upvotes: 1