-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
config.redirects
does not handle trailing slashes
#12532
Comments
@gvkhna given your comment at #7808 (comment) you might have insights on this and maybe found a way to work around this, already? |
I am not sure I understand why this case should be considered, it adds noise in the triaging process. I expect this to not happen, otherwise you should be stuck into a infinite redirect loop.
Since Considering your niche case, I think you should use a middleware to make the redirect yourself. Does it make sense? |
@ematipico thanks for your quick reply 🙏
Let's maybe start here: Is it really a niche case?
Given this, I think there should be a recommended/documented way to set this up properly.
I am trying hard to stay in
Agreed, I also expected this not to happen, but it does. Which is why I was confused to find that
The thing is, that
(I don't understand what you mean by "existing old routes" in my mind every old route is non-existing.)
How can any old route be "existing" in Astros mind? |
Middleware can also be used for static sites, too. It's documented, which is why I suggested it. It runs during the build and it generates static HTML file based on what you return.
It really depends on how you want to serve your files and your host provider. With
I'll need to investigate that. In the meantime, please provide a minimal reproduction. Without that, I'll have to close the issue eventually. |
Hello @tordans. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with |
Thanks for tagging me @tordans. Yes I still maintain as in my comment you tagged me on here: #7808 (comment) would be the correct behavior for this api. After my input was ignored I considered this api broken and gave up, as in however it works is what we have and I myself am very unclear what it's supposed to do and what it actually does. Terrible api but they don't seem to want to fix it. Unfortunately i do agree with @ematipico , if you need specific behavior that isn't supported you'll need to customize through middleware or some other means. I don't think they consider this a bug. However it does work is apparently how it's supposed to work. |
@ematipico thanks for explaining this more…
Here is my minimal reproduction: Test 1
Test 2
|
Here is a good, recent article that talks about this exact issue that I and @gvkhna are trying to solve, a good User- and SEO-Experience with redirects https://bjornlu.com/blog/trailing-slash-for-frameworks Via https://bsky.app/profile/zachleat.com/post/3lczynjv4cc2s It does into details to compare how hoster and server treat the issue. |
To add to this discussion regarding SEO. The issue I face is around the canonical. It's basically broken unless you custom handle it. We discussed this issue over at jonasmerlin/astro-seo#76 The code referenced here <link rel="canonical" href={Astro.props.canonical || Astro.url.href} /> Is what is desired. But in both trailing slash pages, and non-trailing slash pages, the canonical url is specified as that version. So you end up with duplicate canonical's which is a huge issue for SEO. Ideally you pick one as the canonical and redirect from the other. But as it stands the Astro.props.canonical and the trailingSlash configuration property together are broken and don't allow this behavior. @tordans My current workaround is to turn all of this off and handle it correctly through simple but tedious code. This may also be related: jonasmerlin/astro-seo#101 |
@tordans I want to figure out this aspect too. But it seems that even if it would have worked correctly on the Astro end once we upload to netlify/cloudflare URL normalization kicks in and serves both bare and trailingslash versions simultaneously. I’ve made some testings and normalization is absent in Astro server mode and you can configure everything as you desire. But server mode brings a whole new level of complexity and problems. Simpler way for SEO would be to keep those disgusting trailing slashes in place, cause AJAX, Cloudflare, Netlify follow similar standards and redirect them (pretty urls in netlify, normalization in cloudflare). To note though I would still do 301 redirects in cloudflare manually, cause they server 308 code by default which would result in funny things in Google search console |
Astro Info
If this issue only occurs in one browser, which browser is a problem?
Chrome
Describe the Bug
Context
I have an existing site that used to link to /route and /route/ which both rendered the same page.
I am now migrating this site to Astro and want a clean URL structure for both SEO but also to do internal "current page" checks (without looking at both variations).
Goal
Use the
redirects
config to redirect the trailing slash URLs to the non trailing slash URL.Test 1
/route/
works ✅ :Details
/route
also gets redirected to/route
🔴 :Details
Test 2
Following suggestions from #7808 I tried other config options…
/route/
fails withtrailingSlash is set to "never"
🔴 :Details
/route
still fails by redirecting to/route
🔴 :Details
What's the expected result?
redirects: { '/route/': '/route', },
to include the trailing slash in the redirect lookup and only redirect if it is an exact match. I think this should always happen, regardless of thetrailingSlash
setting.redirects: { '/route/': '/route', }, trailingSlash: 'never',
to redirect the/route/
and not show a 404.Link to Minimal Reproducible Example
#12532 (comment)
Participation
The text was updated successfully, but these errors were encountered: