# Routing problems - Apache proxy vs. Webrick direct

**URL:** <https://www.ruby-forum.com/t/routing-problems-apache-proxy-vs-webrick-direct/51722>\
**Category:** Rails\
**Created:** [January 6, 2006, 9:13am UTC](https://www.ruby-forum.com/t/routing-problems-apache-proxy-vs-webrick-direct/51722 "2006-01-06T09:13:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jon\_ASLambert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f08c70/32.png) [@Jon\_ASLambert](https://www.ruby-forum.com/u/Jon_ASLambert)\
**Post date:** [January 6, 2006, 9:13am UTC](https://www.ruby-forum.com/t/routing-problems-apache-proxy-vs-webrick-direct/51722/1 "2006-01-06T09:13:35Z")

</div>

I dropped the use of fastcgi because I could not get popen working (see  
‘[Rails] Apache2 and popen’). It works under WebBrick. Since CGI is  
too  
slow, I thought I’d proxy to WebBrick via Apache.

I am having routing problems now with escaped slashes in the URL.

Here’s my routes.rb:  
map.connect ‘’, :controller =\> “wiki”  
map.connect ‘:controller/service.wsdl’, :action =\> ‘wsdl’  
map.connect ‘:controller/:action/:id’

My request should drop down to the default action.

Here’s my apache vhost configuration:

# ProxyPass / [http://localhost:3000/](http://localhost:3000/)

# ProxyPassReverse / [http://localhost:3000/](http://localhost:3000/)

```
RewriteEngine On
ProxyPreserveHost On
RewriteRule ^/(.*) http://localhost:3000/$1 [P,L]

```

I’ve tried both above, what I have commented out and what I have  
uncommented  
with the same results below.

Here’s the url I request and the not found error in the apache logs:  
10.0.0.2 - - [06/Jan/2006:02:49:19 -0500] “GET  
/repository/index/lib%2Fnet%2F HTTP/1.1” 404 618

And here’s the error in my rails log:

Processing Base#index (for 127.0.0.1 at 2006-01-06 03:01:41) [GET]  
Parameters: {}  
ActionController::RoutingError (Recognition failed for  
“/error/HTTP\_NOT\_FOUND.html.var”):  
c:/apps/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action\_controller/routing.rb:469:in  
`recognition_failed' c:/apps/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/routing.rb:459:in `recognize!’  
c:/apps/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/dispatcher.rb:38:in  
`dispatch' c:/apps/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick_server.rb:117:in `handle\_dispatch’  
c:/apps/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick\_server.rb:83:in  
`service' c:/apps/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service’  
c:/apps/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run' c:/apps/ruby/lib/ruby/1.8/webrick/server.rb:155:in `start\_thread’  
c:/apps/ruby/lib/ruby/1.8/webrick/server.rb:144:in `start' c:/apps/ruby/lib/ruby/1.8/webrick/server.rb:144:in `start\_thread’  
c:/apps/ruby/lib/ruby/1.8/webrick/server.rb:94:in `start' c:/apps/ruby/lib/ruby/1.8/webrick/server.rb:89:in `each’  
c:/apps/ruby/lib/ruby/1.8/webrick/server.rb:89:in `start' c:/apps/ruby/lib/ruby/1.8/webrick/server.rb:79:in `start’  
c:/apps/ruby/lib/ruby/1.8/webrick/server.rb:79:in `start' c:/apps/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick_server.rb:69:in `dispatch’  
c:/apps/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/commands/servers/webrick.rb:59  
c:/apps/ruby/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:21:in  
`require__' c:/apps/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in `require’  
c:/apps/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active\_support/dependencies.rb:214:in  
`require' c:/apps/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/commands/server.rb:28 c:/apps/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in `require\_\_’  
c:/apps/ruby/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:21:in  
`require' c:/apps/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:214:in `require’  
c:/www/xxxxxxxxx/script/server:3  
Rendering  
c:/apps/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action\_controller/templates/rescues/layout.rhtml  
(404 Page Not Found)

It looks like all the params are empty???

Accessing the same URL, except bypassing Apache and using the Webrick  
port I  
get success:

Processing RepositoryController#index (for 10.0.0.2 at 2006-01-06  
03:04:26)  
[GET]  
Parameters: {“action”=\>“index”, “id”=\>“lib/net/”,  
“controller”=\>“repository”}  
Rendering within layouts/repository  
Rendering repository/index  
Completed in 0.63100 (1 reqs/sec) | Rendering: 0.03000 (4%) | DB:  
0.03000  
(4%) | 200 OK  
[[http://xxxxxxxxxxxxxxxxxxxx/repository/index/lib%2Fnet%2F](http://xxxxxxxxxxxxxxxxxxxx/repository/index/lib%2Fnet%2F)]

How do I fix this?

Thanks

J. Lambert

---

<div class="post-metadata">

**Author:** ![Jon\_ASLambert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f08c70/32.png) [@Jon\_ASLambert](https://www.ruby-forum.com/u/Jon_ASLambert)\
**Post date:** [January 6, 2006, 10:01am UTC](https://www.ruby-forum.com/t/routing-problems-apache-proxy-vs-webrick-direct/51722/2 "2006-01-06T10:01:42Z")

</div>

Hi Jon,

I am not very familiar with mod\_rewrite but maybe adding QSA to the  
rule will help?

> ```
> RewriteEngine On
> ProxyPreserveHost On
> RewriteRule ^/(.*) http://localhost:3000/$1 [P,L]
> 
> ```

RewriteRule ^/(.\*) [http://localhost:3000/$1](http://localhost:3000/$1) [QSA, P,L]

As a side note: I have found lighttpd faster and more reliable than  
webrick for development. And I am using proxying Apache → Lightttpd  
setup on my Textdrive account - it works like a charm.

---

<div class="post-metadata">

**Author:** ![Jon\_ASLambert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f08c70/32.png) [@Jon\_ASLambert](https://www.ruby-forum.com/u/Jon_ASLambert)\
**Post date:** [January 6, 2006, 10:40am UTC](https://www.ruby-forum.com/t/routing-problems-apache-proxy-vs-webrick-direct/51722/3 "2006-01-06T10:40:47Z")

</div>

Bragi Ragnarson wrote:

> RewriteRule ^/(.\*) [http://localhost:3000/$1](http://localhost:3000/$1) [QSA, P,L]

Thanks. I gave that a shot but I still get the same errors.

–  
J. Lambert

---

<div class="post-metadata">

**Author:** ![Jon\_ASLambert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f08c70/32.png) [@Jon\_ASLambert](https://www.ruby-forum.com/u/Jon_ASLambert)\
**Post date:** [January 6, 2006, 11:23am UTC](https://www.ruby-forum.com/t/routing-problems-apache-proxy-vs-webrick-direct/51722/4 "2006-01-06T11:23:11Z")

</div>

Jon A. Lambert wrote:

> webbrick.  
> The main difference with this particular controller is the escaping  
> of /'s in the :id part.
> 
> /repository/index/lib%2Fnet%2F

Looks like it’s a mod\_rewrite bug.  
[http://issues.apache.org/bugzilla/show\_bug.cgi?id=34602](http://issues.apache.org/bugzilla/show_bug.cgi?id=34602)

And it’s also a Proxypass bug  
[http://issues.apache.org/bugzilla/show\_bug.cgi?id=29554](http://issues.apache.org/bugzilla/show_bug.cgi?id=29554)

It’s only been broken for a year and a half.

I guess I have to reevaluate how to do this.

I’d like to pass a path to :id. Maybe use separators that won’t be  
stepped  
on by  
apache?

–  
J. Lambert

---

<div class="post-metadata">

**Author:** ![Jon\_ASLambert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f08c70/32.png) [@Jon\_ASLambert](https://www.ruby-forum.com/u/Jon_ASLambert)\
**Post date:** [January 6, 2006, 10:47am UTC](https://www.ruby-forum.com/t/routing-problems-apache-proxy-vs-webrick-direct/51722/5 "2006-01-06T10:47:01Z")

</div>

Jon A. Lambert wrote:

> Bragi Ragnarson wrote:
> 
> > RewriteRule ^/(.\*) [http://localhost:3000/$1](http://localhost:3000/$1) [QSA, P,L]
> 
> Thanks. I gave that a shot but I still get the same errors.

I should add that I am having no trouble at all with other controllers  
in  
this same application using the Apache proxy to webbrick.

The main difference with this particular controller is the escaping of  
/'s  
in the :id part.

/repository/index/lib%2Fnet%2F

–  
J. Lambert

---

<div class="post-metadata">

**Author:** ![Jon\_ASLambert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f08c70/32.png) [@Jon\_ASLambert](https://www.ruby-forum.com/u/Jon_ASLambert)\
**Post date:** [January 6, 2006, 1:17pm UTC](https://www.ruby-forum.com/t/routing-problems-apache-proxy-vs-webrick-direct/51722/6 "2006-01-06T13:17:23Z")

</div>

Jon A. Lambert wrote:

> I’d like to pass a path to :id. Maybe use separators that won’t be  
> stepped on by  
> apache?

I thought I post my solution in case anyone else encounters this.

I rewrote application.

In routes.rb…

map.connect ‘’, :controller =\> “wiki”  
map.connect ‘repository/index/\*path’, :controller =\> “repository”,  
:action  
=\> “index”  
map.connect ‘repository/show/\*path’, :controller =\> “repository”,  
:action  
=\> “show”  
map.connect ‘:controller/service.wsdl’, :action =\> ‘wsdl’  
map.connect ‘:controller/:action/:id’

I pass the rest of the parms in an array. Can’t use \*id for some reason  
above.

Looks like this when the controller gets it.  
Parameters: {“action”=\>“index”, “controller”=\>“repository”,  
“path”=\>[“lib”,  
“net”]}

Also in my views, I couldn’t stuff the path into :id nor :path and use  
link\_to. I expect  
:path gets walked on by the routing code above.

So I had to create me own links.  
\<%= “\<a href=”/repository/index/#{@fpath.empty? ? “”:  
@fpath+’/’}#{f[0…-1]}"\>#{f}" %\>

–  
J. Lambert
