Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirects plugin does not work with URLs - only relative paths #10432

Open
a-ys1 opened this issue Jan 7, 2025 · 0 comments
Open

Redirects plugin does not work with URLs - only relative paths #10432

a-ys1 opened this issue Jan 7, 2025 · 0 comments
Labels
status: needs-triage Possible bug which hasn't been reproduced yet

Comments

@a-ys1
Copy link

a-ys1 commented Jan 7, 2025

Describe the Bug

When using the redirects plugin:

Example 1: This does not work
Image

Example 2: This works
Image

If you do as in Example 1, you have to prepend the process.env.NEXT_PUBLIC_SERVER_URL in each route (e.g [slug]) to the url. On this line:
https://github.com/payloadcms/payload/blob/main/templates/website/src/app/(frontend)/%5Bslug%5D/page.tsx#L51

Otherwise the PayloadRedirects-component will look for a redirect with the URL matching the relative path.
https://github.com/payloadcms/payload/blob/main/templates/website/src/components/PayloadRedirects/index.tsx#L17

So, the redirects plugin says "From URL" but actually needs a relative path as of now.

A solution could be to prepend the NEXT_PUBLIC_SERVER_URL to the url-prop inside the PayloadRedirects-component since that somewhat encapsulates the redirect logic.

Link to the code that reproduces this issue

https://github.com/payloadcms/payload/blob/main/templates/website/src/components/PayloadRedirects/index.tsx#L17

Reproduction Steps

  1. npx create-payload app - select website template, next coming options are irrelevant
  2. Create a page called first-testpage
  3. Create a page called second-testpage
  4. Delete the page in step 2
  5. Add a redirect with the From URL as [BASE_URL]/first-testpage
  6. Set the to To URL Type as [BASE_URL]/second-testpage
  7. Visit [BASE_URL]/first-testpage, you should get a 404

Which area(s) are affected? (Select all that apply)

plugin: other, area: templates

Environment Info

Payload: v.3.0.15
Node: v20.18.0
Next.js: 15.1.0
@a-ys1 a-ys1 added status: needs-triage Possible bug which hasn't been reproduced yet validate-reproduction labels Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs-triage Possible bug which hasn't been reproduced yet
Projects
None yet
Development

No branches or pull requests

1 participant