# How to create a dynamic 404 page?

**URL:** <https://www.ruby-forum.com/t/how-to-create-a-dynamic-404-page/118678>\
**Category:** Rails\
**Created:** [October 30, 2007, 12:21am UTC](https://www.ruby-forum.com/t/how-to-create-a-dynamic-404-page/118678 "2007-10-30T00:21:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [October 30, 2007, 12:21am UTC](https://www.ruby-forum.com/t/how-to-create-a-dynamic-404-page/118678/1 "2007-10-30T00:21:33Z")

</div>

Hi all

When a user of my website reaches a page that doesn’t exist, the  
404.html page is rendered and the header status 404 is sent.  
I’d like to have this 404 page dynamic, e.g. I’d like to display the  
user a mailto link with subject that contains the actual link of the  
document that was not found:

[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)?subject=Broken link -  
[http://this-link-does-not-exist](http://this-link-does-not-exist)

How can I achieve that? I don’t want to use JavaScript or such stuff,  
I’d like to have full access to the “normal” Rails environment in  
404.html…

Thanks  
Josh

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [October 30, 2007, 3:28am UTC](https://www.ruby-forum.com/t/how-to-create-a-dynamic-404-page/118678/2 "2007-10-30T03:28:45Z")

</div>

I think you can overwrite the 404.html file in the public dir, though  
that wouldn’t give you full access to the rails env.

I think you could also set up a catch all route and direct to a  
specific action, which would in essence work as a 404. In that action  
you’d have to set the 404 status and return the page.

There is more than likely a simpler way that I’m just unfamiliar with  
that someone will be swooping in with, but those were just the two  
ideas that came to the top of my head.

On Oct 29, 6:21 pm, Joshua M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
