# Quick routes question

**URL:** <https://www.ruby-forum.com/t/quick-routes-question/112874>\
**Category:** Rails\
**Created:** [August 24, 2007, 1:41am UTC](https://www.ruby-forum.com/t/quick-routes-question/112874 "2007-08-24T01:41:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 24, 2007, 1:41am UTC](https://www.ruby-forum.com/t/quick-routes-question/112874/1 "2007-08-24T01:41:20Z")

</div>

I have

# This is a catch-all for routes that don’t exist, visitor is

redirected to home page.  
ActionController::Routing::Routes.draw do |map|  
map.connect ‘:controller/:action/:id’  
map.connect ‘\*path’, :controller =\> ‘home’  
end

in my routes.rb file.  
This works fine to redirect to the home page if somebody types a wrong  
or missing address into the web browser.  
But it doesn’t change the url/uri displayed in the browser.

How can I change the url/uri to display what it should be? (in this  
case, domain followed by /home)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 24, 2007, 1:53am UTC](https://www.ruby-forum.com/t/quick-routes-question/112874/2 "2007-08-24T01:53:21Z")

</div>

Nevermind, I’ve found a simple solution that works:  
I’ve simply made the catch-all route controller/action go to a  
controller where I def’d an action method that creates a flash message  
and redirects to the home page.

In routes.rb:

# This is a catch-all for routes that don’t exist, visitor is

redirected to home page.  
ActionController::Routing::Routes.draw do |map|  
map.connect ‘:controller/:action/:id’  
map.connect ‘\*path’, :controller =\> ‘home’, :action =\>  
‘catcher’#:controller =\> ‘home’, :action =\> ‘index’  
end

In the corresponding controller:

def catcher  
flash[:notice] = ‘Seems that the page you were looking for does  
not exist, so you’ve been redirected here.’  
redirect\_to :action =\> ‘index’  
end

It’s not the most sophisticated thing but it works.  
Does anybody know the param to include in my flash message to display  
the originally requested address?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 24, 2007, 1:54am UTC](https://www.ruby-forum.com/t/quick-routes-question/112874/3 "2007-08-24T01:54:21Z")

</div>

On Aug 23, 2007, at 6:39 PM, removed\_email\_address@domain.invalid wrote:

> ```
> map.connect '*path', :controller => 'home'
> 
> ```

You could route this to a “redirect\_home” action that calls  
redirect\_to /home

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 24, 2007, 2:16am UTC](https://www.ruby-forum.com/t/quick-routes-question/112874/4 "2007-08-24T02:16:22Z")

</div>

Ah, Thanks Mr. Ivey, but it looks like my watery brain kicked in just  
minutes before your post! I already came to that conclusion.  
That said, I can see where adding loggin for this catcher method could  
generate useful SEO data for site features or simply routes that  
_should_ be added! Of course it is also a good way to catch malicious  
visitors that should be banned in the htaccess file.
