# "true" wildcard in routes.rb

**URL:** <https://www.ruby-forum.com/t/true-wildcard-in-routes-rb/49872>\
**Category:** Rails\
**Created:** [December 9, 2005, 3:35pm UTC](https://www.ruby-forum.com/t/true-wildcard-in-routes-rb/49872 "2005-12-09T15:35:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![lkoskela](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/a5b964/32.png) [@lkoskela](https://www.ruby-forum.com/u/lkoskela)\
**Post date:** [December 9, 2005, 3:35pm UTC](https://www.ruby-forum.com/t/true-wildcard-in-routes-rb/49872/1 "2005-12-09T15:35:45Z")

</div>

Hi,

I’d like to catch certain type of URLs that follow the pattern  
“[http://server.com/map/http://www.another.com/url/with.php?possible=arguments](http://server.com/map/http://www.another.com/url/with.php?possible=arguments)”  
and map that to a controller which gets \*whatever comes after “/map/” as  
a single variable.

I already tried the following mapping:

map.connect '/map/_all’,  
:controller =\> ‘urlmapper’,  
:action =\> ‘test’,  
:all =\> /._/

and in the controller then concatenating the resulting “all” array into  
a single string, but that only works when there’s no URL request  
parameters (“?foo=bar”).

What would be the “Rails way” to do what I’m describing here?

And thanks for “listening” 🙂

---

<div class="post-metadata">

**Author:** ![lkoskela](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/a5b964/32.png) [@lkoskela](https://www.ruby-forum.com/u/lkoskela)\
**Post date:** [December 9, 2005, 7:18pm UTC](https://www.ruby-forum.com/t/true-wildcard-in-routes-rb/49872/2 "2005-12-09T19:18:32Z")

</div>

On 12/9/05, Lasse K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> and in the controller then concatenating the resulting “all” array into  
> a single string, but that only works when there’s no URL request  
> parameters (“?foo=bar”).

You need to URL encode the ‘?’ if you don’t want it to be picked up as  
a querystring separator.

–  
Regards,  
John W.

> **[John Wilger](http://johnwilger.com)**
>
> The personal website of John Wilger; Dad, Cyclist, Software Developer

* * *

Alice came to a fork in the road. “Which road do I take?” she asked.  
“Where do you want to go?” responded the Cheshire cat.  
“I don’t know,” Alice answered.  
“Then,” said the cat, “it doesn’t matter.”

- Lewis Carrol, Alice in Wonderland

---

<div class="post-metadata">

**Author:** ![lkoskela](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/a5b964/32.png) [@lkoskela](https://www.ruby-forum.com/u/lkoskela)\
**Post date:** [December 9, 2005, 7:26pm UTC](https://www.ruby-forum.com/t/true-wildcard-in-routes-rb/49872/3 "2005-12-09T19:26:06Z")

</div>

johnwilger wrote:

> On 12/9/05, Lasse K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > and in the controller then concatenating the resulting “all” array into  
> > a single string, but that only works when there’s no URL request  
> > parameters (“?foo=bar”).
> 
> You need to URL encode the ‘?’ if you don’t want it to be picked up as  
> a querystring separator.

Thanks John. I was aware of the query string being treated as a query  
string. I’m just wondering if someone somewhere has already implemented  
some kind of a utility/tweak to “fake” the path and query string into a  
single string.

Can we access the original request URL from a controller?

-Lasse-

---

<div class="post-metadata">

**Author:** ![lkoskela](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/a5b964/32.png) [@lkoskela](https://www.ruby-forum.com/u/lkoskela)\
**Post date:** [December 9, 2005, 7:36pm UTC](https://www.ruby-forum.com/t/true-wildcard-in-routes-rb/49872/4 "2005-12-09T19:36:39Z")

</div>

Lasse wrote:

> Can we access the original request URL from a controller?

Sorry for asking something that’s in the RDocs… Yeah, there’s  
“request.request\_uri” which returns the full path including query  
string. I suppose I could just parse that to pick up the URL from the  
end.

---

<div class="post-metadata">

**Author:** ![lkoskela](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/a5b964/32.png) [@lkoskela](https://www.ruby-forum.com/u/lkoskela)\
**Post date:** [December 13, 2005, 1:38am UTC](https://www.ruby-forum.com/t/true-wildcard-in-routes-rb/49872/5 "2005-12-13T01:38:40Z")

</div>

No need to parse.

A route like:  
map.connect ‘serve/\*commands’, :controller =\> ‘serve’

Will yield an array called ‘commands’ in your controller. 🙂

- Rabbit

* * *

---

<div class="post-metadata">

**Author:** ![lkoskela](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/a5b964/32.png) [@lkoskela](https://www.ruby-forum.com/u/lkoskela)\
**Post date:** [December 13, 2005, 1:44am UTC](https://www.ruby-forum.com/t/true-wildcard-in-routes-rb/49872/6 "2005-12-13T01:44:43Z")

</div>

I should note that ‘commands’ is available in params.  
(params[:commands])

- Rabbit

* * *
