#Redirect plugin capitalizing base url

29 messages · Page 1 of 1 (latest)

pulsar horizon
#

I have added a redirect:

From: http://localhost:3000/en/third-testpage
To: http://localhost:3000/en/second-testpage

When i visit http://localhost:3000/en/second-testpage I get sent to the 404 page because the redirect plugin fails to find the corresponding redirect. When I log the redirects object I can see that localhost is capitalized as Localhost (see image).

Here are my console.log´s placed:

/* This component helps us with SSR based dynamic redirects */
export const PayloadRedirects: React.FC<Props> = async ({ disableNotFound, url }) => {
const redirects = await getCachedRedirects()()
// console.log(url);
console.log('redirects', redirects);

const redirectItem = redirects.find((redirect) => redirect.from === url)

console.log('redirecteditem', redirectItem);
...

I just upgraded from Paylod v.3.9.0 to v3.15.0, but the problem was there before. And yes, I have doublechecked that I myself didn´t capitalize the url. Has anyone ran into this problem?

carmine galeBOT
pulsar horizon
#

Here is what happens when I hardcode the URL in the find, I get redirected but it fails somehow

lament lance
#

Hey @pulsar horizon,

That's weird. Can you reproduce this in a fresh website template?

pulsar horizon
#

Hey @lament lance,

Just tested with a fresh website template, the redirects are not working it seems. I'm not sure if it´s due to capitalization, since it´s only capitalized when i log it in Firefox but not in terminal or Chrome.

The code just reaches the notFound() at the bottom of the PayloadRedirects-component

#

It´s this line in the PayloadRedirects-component that returns undefined:
const redirectItem = redirects.find((redirect) => redirect.from === url)

lament lance
#

Hmm, how strange. I appreciate you reproducing it in a fresh template! Thank you

#

The capitalization is actually quite odd too since urls are case sensitive

#

Well, atleast on non-windows systems

#

Can you share your redirects plugin config? Nvm, it's a fresh template! I'll check it out

pulsar horizon
#

No worries! I´m on Windows btw. I just tried the internal link option as well for the redirect but same outcome

pulsar horizon
#

@lament lance I found the solution...

lament lance
#

What've you found my friend

pulsar horizon
#

I don´t know if it´s UX that can be improved, but I think it shouldn´t say From URL in the redirects plugin when it doesn´t accept a full URL, just relative URL...

What I did in the image works

#

I´m guessing a lot of users will be confused when they enter a URL but they need to enter a path instead

lament lance
#

Ah

#

So with a relative path it's working now?

#

I somehow always forget this is a thing

#

You're right, it's confusing

pulsar horizon
#

Yes it´s working with relative path. When I log the URL in PayloadRedirects, it´s /third-testpage

#

I think this needs to fixed somehow, end users will probably not figure this out

#

Should I create it as a design issue maybe?

lament lance
#

Sounds fine to me

#

Should be a simple fix

pulsar horizon
#

Yeah, I agree. Thanks for the mental support😀

lament lance
#

My pleasure, glad you figured it out!

pulsar horizon
#

@lament lance One thing though, I´m not sure if it´s really a design bug though since it could be solved by just prepending the SERVER_URL to the url? Payload can´t really provide us with that since Next.js just gives us the relative path from the slug

`
type Args = {
params: Promise<{
slug?: string
}>
}

export default async function Page({ params: paramsPromise }: Args) {
const { isEnabled: draft } = await draftMode()
const { slug = 'home' } = await paramsPromise
const url = process.env.NEXT_PUBLIC_SERVER_URL + '/' + slug

let page: PageType | null

page = await queryPageBySlug({
slug,
})

if (!page) {
return <PayloadRedirects url={url} />
}`

#

See the url assignment

lament lance
#

Hmm, I think you can just open a standard issue