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 not working (vercel static) #9259

Closed
1 task done
digitaltopo opened this issue Nov 30, 2023 · 4 comments · Fixed by #9287
Closed
1 task done

Redirects not working (vercel static) #9259

digitaltopo opened this issue Nov 30, 2023 · 4 comments · Fixed by #9287
Assignees
Labels
- P4: important Violate documented behavior or significantly impacts performance (priority) feat: redirects Related to the redirects feature (scope) pkg: vercel Related to Vercel adapter (scope)

Comments

@digitaltopo
Copy link

Astro Info

Astro                    v3.3.0
Node                     v18.17.0
System                   Linux (x64)
Package Manager          npm
Output                   static
Adapter                  @astrojs/vercel
Integrations             astro-icon
                         @astrojs/react
                         @astrojs/mdx
                         unocss
                         astro-robots
                         @astrojs/partytown

✅ I am using a version of Node that Astro supports (>=18.14.1)

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

Redirects don't seem to be working correctly. I have two cases in which they fail:

Case 1: Regular redirects don't work

I'm trying to redirect /posts to /blog. There are no pages or content associated with /posts. Doesn't seem to be redirecting, just goes to the 404 page. I've tried creating a posts.astro file in my pages directory, but it doesn't help.

astro.config.mjs:

...
redirects: {
 '/posts' : '/blog'
}

Case 2: Redirecting to an external website

astro.config.mjs:

...
redirects: {
 '/docs' : 'https://docs.somewebsite.com'
}

This works fine in development, but shows the 404 page on live deployments.

I am running Astro with static output and deployed on vercel

Am I missing something here or incorrectly configuring redirects?

What's the expected result?

Expecting the configured redirects to work.

In the MRE below things work fine.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-boqzze?file=astro.config.mjs

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Nov 30, 2023
@lilnasy lilnasy added - P4: important Violate documented behavior or significantly impacts performance (priority) pkg: vercel Related to Vercel adapter (scope) feat: redirects Related to the redirects feature (scope) and removed needs triage Issue needs to be triaged labels Dec 4, 2023
@lilnasy lilnasy self-assigned this Dec 4, 2023
@imosan
Copy link

imosan commented Dec 15, 2023

The issue has been resolved in version 6.1.0 of @astrojs/vercel. However, if there is a trailing "/" in the redirect key string, it may still not work.

...
redirects: {
 '/resume/' : '/qualifications'
}

@lilnasy
Copy link
Contributor

lilnasy commented Dec 15, 2023

@imosan I tried this and the resulting vercel files were the same as if /resume/ did not have a trailing slash. If it breaks for you, there might be something else at play. Could you open a new issue?

@imosan
Copy link

imosan commented Dec 16, 2023

@lilnasy Thank you for your reply. I tried removing the redirection definition for "/resume/", but "qualifications" still did not redirect and resulted in a 404 error. When loading the actual file qualifications.astro, the page is displayed regardless of the presence of a trailing "/". However, only those with redirection definitions seem to result in a 404 when a "/" is added at the end. Should we consider the possibility that this is an issue with astrojs itself?

By the way, with npm run dev, it redirects without any issues regardless of the presence or absence of trailing "/" in the redirect definition. Thanks

p.s. something related to DNS?

@sonim1
Copy link

sonim1 commented Feb 8, 2024

@lilnasy Thank you for your reply. I tried removing the redirection definition for "/resume/", but "qualifications" still did not redirect and resulted in a 404 error. When loading the actual file qualifications.astro, the page is displayed regardless of the presence of a trailing "/". However, only those with redirection definitions seem to result in a 404 when a "/" is added at the end. Should we consider the possibility that this is an issue with astrojs itself?

By the way, with npm run dev, it redirects without any issues regardless of the presence or absence of trailing "/" in the redirect definition. Thanks

p.s. something related to DNS?

I solved this issue in Vercel using static redirects.

https://vercel.com/docs/edge-network/redirects#configuration-redirects

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P4: important Violate documented behavior or significantly impacts performance (priority) feat: redirects Related to the redirects feature (scope) pkg: vercel Related to Vercel adapter (scope)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants