#Dispalying original/redirected path in custom 404

3 messages · Page 1 of 1 (latest)

cedar flame
#

Hey everyone, how is it going?
I've been loving the migration from SvelteKit to Astro, for my blog.

I ran into any issue with my custom 404 page:

<h1 class="text-5xl font-black leading-tight">Page Not Found</h1>

<p class="max-w-[40ch] text-sm">
  <code> {Astro.url.pathname} </code>
  does not exist.
</p>

This works well on the development server but doesn't in production.
I'm deploying it to Cloudlfare Pages, with the hybrid output mode.

Is there a solution for this?

This feature is definitely a "nice to have" on my blog, but it might block others.
In the future, I plan to maybe add a feature that searches for existing pages that are similar to the page that the user expected to exist but doesn't.

Thank you for your time!

coral folioBOT
#

Hi @cedar flame. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Hello! I'm glad to hear that you're enjoying your migration to Astro.

The issue you're experiencing might be related to the way Astro handles custom 404 pages in production. In development, Astro can serve your custom 404 page correctly, but in production, it might not behave as expected. This is a known issue that has been reported in the Astro GitHub repository (source (https://github.com/withastro/astro/issues/4113)).

As for displaying the original or redirected path in the custom 404 page, it seems that Astro doesn't currently support this feature out of the box. There's a discussion on a similar topic in the Astro GitHub repository, where a contributor suggested a workaround by rendering an Astro component from within the page (source (https://github.com/withastro/astro/issues/4635)). However, this might not be the ideal solution for your case.

For your future plan to add a feature that searches for existing pages similar to the non-existing page, you might need to implement a custom solution, as Astro doesn't provide this feature natively.

I recommend keeping an eye on the Astro GitHub repository for updates on these issues and potential new features. You can also consider contributing to the project if you have a solution in mind. Astro is an open-source project and contributions are always welcome!

I hope this information helps! Let me know if you have any other questions.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: