# Redirect in routes.rb

**URL:** <https://www.ruby-forum.com/t/redirect-in-routes-rb/93148>\
**Category:** Rails\
**Created:** [April 28, 2007, 8:37am UTC](https://www.ruby-forum.com/t/redirect-in-routes-rb/93148 "2007-04-28T08:37:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Helene\_Jonsson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/e56c9b/32.png) [@Helene\_Jonsson](https://www.ruby-forum.com/u/Helene_Jonsson)\
**Post date:** [April 28, 2007, 8:37am UTC](https://www.ruby-forum.com/t/redirect-in-routes-rb/93148/1 "2007-04-28T08:37:59Z")

</div>

Hi:

Is there a way I could do redirect directly in routes.rb file and then  
use some friendly link\_to in my views. i.e. not to repeat  
[.xyz Domain Names | Join Generation XYZ](http://xyz.com/redirect1), [.xyz Domain Names | Join Generation XYZ](http://xyz.com/redirect2) etc…

Maybe a re-direct controller of some sort… is there such plugin  
available…??

Regards.

---

<div class="post-metadata">

**Author:** ![Helene\_Jonsson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/e56c9b/32.png) [@Helene\_Jonsson](https://www.ruby-forum.com/u/Helene_Jonsson)\
**Post date:** [April 30, 2007, 2:51pm UTC](https://www.ruby-forum.com/t/redirect-in-routes-rb/93148/2 "2007-04-30T14:51:37Z")

</div>

Best solution I’ve found is to use a catchall route glob at the end of  
my  
routes and use that method to test for certain conditions, like this…

[routes.rb]

map.with\_options :controller =\> “application” do |m|  
map.index “/”, :action =\> “index”  
map.page “/:url”, :action =\> “page”  
map.catcher “/\*whatever”, :action =\> “catcher”  
end

[application.rb]

# index and page as normal

def catcher

# Test params[:whatever] for what you might want to redirect

specifically

# Remember it’s an Array though.

if params[:whatever][0] == “whatever”  
# Whatever…  
else  
# Something else…  
end  
end

Hope that helps.

RSL
