-
-
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
Invalid URL error when domain contains multiple slashes at the end #12722
Comments
I can only reproduce this in one scenario: when running |
I discovered it when deployed to Cloudflare Pages and accidentally put two // at the end and to my surprise, the page loaded keeping them. So I added more and they stayed too. I spent quite a good amount of time fighting with CF deployment and ultimately did localhost testing to see the invalid URL error. I would love to see Astro paying attention to slashes, as someone who built their first website in 1998 and cut their teeth on SEO. I know that to this day (crazy!) Google can't resolve the issue with slashes at the end of URLs and they're treated as two different competing addresses that harm SEO. And users link in various surprising and often incorrect ways. |
So to be clear, there are two issues? Locally, there's the invalid URL problem, and on Cloudflare it's that multiple slashes are ignored and treated the same as a single slash? |
Hmmm I'm not sure if it's one issue that behaves differently depending on the environment or two separate ones. I'll deploy basic clean version to CF again to see if the behavior is the same. |
The code with the invalid URL is in the dev server code, so if it also happens elsewhere then it's two issues. |
After extensive testing I can confirm this is a framework-level issue that needs attention. I've tested various scenarios with comparison to Next.js and here's what I found:
I've tried various approaches to fix this on Cloudflare Pages:
None of these approaches properly handled multiple slashes. Test cases that should all redirect to their canonical form (currently Astro preserves all these variations): domain.com// After more testing I found that the issue occurs in two specific cases: Case 1: Multiple slashes at root path Case 2: Multiple slashes before subpath Case 3: Multiple slashes after subpath (works correctly) Compare with Next.js (always normalizes regardless of pattern) For a framework that puts such emphasis on Core Web Vitals and SEO I believe this should be handled at the framework level similar to how Next.js does it. Let me know if you need any help with testing different approaches to fix this. Thanks! |
Is there anything else needed @ascorbic? |
@screenfluent there's a PR open already, we're essentially looking for a way to fix the issue. Please bear with us |
This is something that's probably going to need to be implemented in an adapter-by-adapter way, because the built-in redirects don't support the syntax to implement this. I have a PR to handle it in dev, but we'll need to probably do separate fixes for Cloudflare etc. |
Many thanks guys! I've found so much joy since I started learning Astro recently. It literally transported me 20+ years back to when I was building HTML sites. Just when everything was looking great with 5.0, I discovered one of the worst technical SEO nightmare. And since some time past was worried that nothing will happen. Anyway, I hope you'll figure it out. For the dev server, it doesn't matter to me at all. I just learned the hard way that Google can be unforgiving when links I have no control over got some typos. |
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
Astro throws 500 Internal Server Error with "Invalid URL" when main domain contains double or more slashes at the end. This happens in development server, production build, StackBlitz. This is not a browser issue. The problem occurs at server level and can be reproduced with curl.
What's the expected result?
Instead the server crashes with 500 error.
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-726xsb6l-xoqxvvkc
Participation
The text was updated successfully, but these errors were encountered: