# How to route localhost:3000/redirect/www.google.com?

**URL:** <https://www.ruby-forum.com/t/how-to-route-localhost-3000-redirect-www-google-com/171497>\
**Category:** Rails\
**Created:** [July 3, 2009, 3:22pm UTC](https://www.ruby-forum.com/t/how-to-route-localhost-3000-redirect-www-google-com/171497 "2009-07-03T15:22:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![arunmehta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ac91a4/32.png) [@arunmehta](https://www.ruby-forum.com/u/arunmehta)\
**Post date:** [July 3, 2009, 3:22pm UTC](https://www.ruby-forum.com/t/how-to-route-localhost-3000-redirect-www-google-com/171497/1 "2009-07-03T15:22:11Z")

</div>

I would like to filter all incoming pages via my local rails server,  
so I would like to access the web by typing a url into my browser  
along the lines of:

[http://localhost:3000/redirect/www.google.com](http://localhost:3000/redirect/www.google.com)

I have a controller called redirect already, in it is a function  
called  
index just waiting to process the incoming url, which it hopes to  
find in params[:id]

Now, could some kind soul, please tell me what line to add to  
my config/routes.rb so that this works?

I tried reading

> **[Beginners Tutorial: Routing in Rails 2.0 (with REST) – Part 1 of n](https://darynholmes.wordpress.com/2008/03/15/beginners-tutorial-routing-in-rails-20-with-rest-part-1-of-n/)**
>
> Part 2 About this series This is a series for beginners wanting to learn about routing in Rails 2.0. This first post is aimed at exploring the behaviour of routing in Rails. It examines what happen…

to find out, and while I thought it was a great tutorial, it did not  
seem to be getting to my problem quickly enough.

Gratefully,  
Arun

---

<div class="post-metadata">

**Author:** ![arunmehta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ac91a4/32.png) [@arunmehta](https://www.ruby-forum.com/u/arunmehta)\
**Post date:** [July 3, 2009, 4:24pm UTC](https://www.ruby-forum.com/t/how-to-route-localhost-3000-redirect-www-google-com/171497/2 "2009-07-03T16:24:30Z")

</div>

arunmehta wrote:

> I would like to filter all incoming pages via my local rails server,

Huh? What exactly are you trying to do here?

> so I would like to access the web by typing a url into my browser  
> along the lines of:
> 
> [http://localhost:3000/redirect/www.google.com](http://localhost:3000/redirect/www.google.com)
> 
> I have a controller called redirect already, in it is a function  
> called  
> index just waiting to process the incoming url, which it hopes to  
> find in params[:id]
> 
> Now, could some kind soul, please tell me what line to add to  
> my config/routes.rb so that this works?

Well, let’s think about this. The path is ‘/redirect’ followed by the  
URL to redirect to. That means that we can express it as  
‘/redirect/:url’.

The controller is redirect, and the action is index.

And let’s give the route the name of redirect.

Put that all together and you get  
map.redirect ‘/redirect/:url’, :controller =\> ‘redirect’, :action =\>  
‘index’

Does that make sense?

> I tried reading  
> [Beginners Tutorial: Routing in Rails 2.0 (with REST) – Part 1 of n | Agile Practitioners](http://darynholmes.wordpress.com/2008/03/15/beginners-tutorial-routing-in-rails-20-with-rest-part-1-of-n/)  
> to find out, and while I thought it was a great tutorial, it did not  
> seem to be getting to my problem quickly enough.

What you actually should be reading is the Routing docs right in the  
Rails API docs!

> Gratefully,  
> Arun

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid
