Issue with redirect handling
DavidRouyer opened this issue · comments
I'm trying to make redirect 2 distincts URLs into one.
/test
and /test2
into notatest
.
I tried
{ from: '^/test', to: '/notatest', statusCode: 301 }, { from: '^/test2', to: '/notatest', statusCode: 301 },
And
{ from: '^/test(.*)', to: '/notatest', statusCode: 301 },
With the same result: /test
redirects to notatest
and /test2
redirects to /notatest2
instead of /notatest
.
^/test
still matches /test2
so it seems expected.
You can try either:
- ending first rule with
$
(end-of-line) to match exactly/test
and nothing else - add
\b
at the end of^/test
to match word boundary
Thank you for your answer @rchl .
I tried { from: '^/test$', to: '/notatest', statusCode: 301 }, { from: '^/test2$', to: '/notatest', statusCode: 301 },
and
{ from: '^/test\b', to: '/notatest', statusCode: 301 }, { from: '^/test2\b', to: '/notatest', statusCode: 301 },
and I still have the same behavior
It works for me with:
{ from: '^/test$', to: '/first', statusCode: 301 },
{ from: '^/test2$', to: '/second', statusCode: 301 },
First redirects to /first
and second to /second
.
When testing, disable browser cache (in Chrome inspector if using that) as 301 is permanent redirect cached by browser so that might be confusing you.
Yes, it works! Thank you for your help!