# Apache, mongrel and slash in route variable

**URL:** <https://www.ruby-forum.com/t/apache-mongrel-and-slash-in-route-variable/144929>\
**Category:** Deployment\
**Created:** [August 4, 2008, 1:50pm UTC](https://www.ruby-forum.com/t/apache-mongrel-and-slash-in-route-variable/144929 "2008-08-04T13:50:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tracerek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/439d5e/32.png) [@tracerek](https://www.ruby-forum.com/u/tracerek)\
**Post date:** [August 4, 2008, 1:50pm UTC](https://www.ruby-forum.com/t/apache-mongrel-and-slash-in-route-variable/144929/1 "2008-08-04T13:50:14Z")

</div>

Hi,  
in my app i’m ussing this route mapping map.connect  
“:controller/:action/view/:file” where :file can have another slash  
inside (eg. /config/basics/view/some\_folder/another\_file) . While  
accesing this link in FF3 adress panel its shown like  
/config/basics/view/some\_folder%2Fanother\_file. Under mongrel it works  
well, but when I connect mongrel to apache it shows “Not Found” error  
page.  
I’m on windows, apache 2.2, using configuration of vrtual hosts:

\<VirtualHost \*:80\>  
ServerName [yourdomain.com](http://yourdomain.com)  
DocumentRoot D:/myapp/public  
\<Directory “D:/myapp/public”\>  
Options FollowSymLinks  
AllowOverride None  
Order allow,deny  
Allow from all

# Configure mongrel instances

\<Proxy balancer://mongrel\_cluster\>  
BalancerMember [http://127.0.0.1:4001](http://127.0.0.1:4001)  
BalancerMember [http://127.0.0.1:4002](http://127.0.0.1:4002)  
BalancerMember [http://127.0.0.1:4003](http://127.0.0.1:4003)  
BalancerMember [http://127.0.0.1:4004](http://127.0.0.1:4004)  
BalancerMember [http://127.0.0.1:4005](http://127.0.0.1:4005)  
  
RewriteEngine On

# Uncomment for rewrite debugging

#RewriteLog logs/your\_app\_deflate\_log deflate  
#RewriteLogLevel 9

# Check for maintenance file and redirect all requests

RewriteCond %{DOCUMENT\_ROOT}/system/maintenance.html -f  
RewriteCond %{SCRIPT\_FILENAME} !maintenance.html  
RewriteRule ^.\*$ /system/maintenance.html [L]

# Rewrite index to check for static

RewriteRule ^/$ /index.html [QSA]

# Rewrite to check for Rails cached page

RewriteRule ^([^.]+)$ $1.html [QSA]

# Redirect all non-static requests to cluster

RewriteCond %{DOCUMENT\_ROOT}/%{REQUEST\_FILENAME} !-f  
RewriteRule ^/(.\*)$ balancer://mongrel\_cluster%{REQUEST\_URI} [P,QSA,L]

# Deflate

AddOutputFilterByType DEFLATE text/html text/plain text/xml  
BrowserMatch ^Mozilla/4 gzip-only-text/html  
BrowserMatch ^Mozilla/4.0[678] no-gzip  
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

# Uncomment for deflate debugging

#DeflateFilterNote Input input\_info  
#DeflateFilterNote Output output\_info  
#DeflateFilterNote Ratio ratio\_info  
#LogFormat ‘“%r” %{output\_info}n/%{input\_info}n (%{ratio\_info}n%%)’  
deflate  
#CustomLog logs/your\_app\_deflate\_log deflate  
ErrorLog logs/your\_app\_error\_log  
CustomLog logs/your\_access\_log combined

I’ve just followed some tutorials with this configuration and in fact I  
really don’t know what I was doing there, so any help with that will be  
great. 🙂 I think I need to add some rule for mod\_rewrite, but for now  
I really know nothing about it.  
Is there any chance to get it working, or only way to do it is to  
rewrite my app to not using slashes in route variables?

thanks

---

<div class="post-metadata">

**Author:** ![tracerek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/439d5e/32.png) [@tracerek](https://www.ruby-forum.com/u/tracerek)\
**Post date:** [August 4, 2008, 5:06pm UTC](https://www.ruby-forum.com/t/apache-mongrel-and-slash-in-route-variable/144929/2 "2008-08-04T17:06:20Z")

</div>

You need to configure Apache to allow encoded slashes. By default, it  
does not allow them.

[http://httpd.apache.org/docs/2.2/mod/core.html#allowencodedslashes](http://httpd.apache.org/docs/2.2/mod/core.html#allowencodedslashes)

–  
Doug Barth

---

<div class="post-metadata">

**Author:** ![tracerek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/439d5e/32.png) [@tracerek](https://www.ruby-forum.com/u/tracerek)\
**Post date:** [August 4, 2008, 5:21pm UTC](https://www.ruby-forum.com/t/apache-mongrel-and-slash-in-route-variable/144929/3 "2008-08-04T17:21:44Z")

</div>

wow. Thank you very much, but I’m affraid it isn’t that simple… I’ve  
added it to my virtualhosts configuration:

\<VirtualHost \*:80\>  
AllowEncodedSlashes On  
ServerName [yourdomain.com](http://yourdomain.com)  
.  
.  
.

and now it shows Rails 404 instead of Apache 404…

Any ideas?

Doug Barth wrote:

> You need to configure Apache to allow encoded slashes. By default, it  
> does not allow them.
> 
> [core - Apache HTTP Server Version 2.2](http://httpd.apache.org/docs/2.2/mod/core.html#allowencodedslashes)
> 
> –  
> Doug Barth

---

<div class="post-metadata">

**Author:** ![tracerek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/439d5e/32.png) [@tracerek](https://www.ruby-forum.com/u/tracerek)\
**Post date:** [August 4, 2008, 6:12pm UTC](https://www.ruby-forum.com/t/apache-mongrel-and-slash-in-route-variable/144929/4 "2008-08-04T18:12:37Z")

</div>

What error are you getting in your Rails log file? If it’s a routing  
error, you may need to specify that the :file portion of your route  
can contain pretty much anything.

map.connect “:controller/:action/view/:file”, :requirements =\>  
{:file =\> /.\*/}

–  
Doug Barth

---

<div class="post-metadata">

**Author:** ![tracerek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/439d5e/32.png) [@tracerek](https://www.ruby-forum.com/u/tracerek)\
**Post date:** [August 4, 2008, 7:04pm UTC](https://www.ruby-forum.com/t/apache-mongrel-and-slash-in-route-variable/144929/5 "2008-08-04T19:04:59Z")

</div>

Yop that was true. 🙂

This add screwed up this route  
map.connect “:controller/:action/edit/:file/:id”,  
:mode =\> “edit”,  
:requirements =\> {:file =\> /.\*/},  
:file =\> nil,  
:id =\> nil

But splitting it to  
map.connect “:controller/:action/edit/:id/:file”,  
:mode =\> “edit”,  
:requirements =\> {:file =\> /._/, :id =\> /\d+/},  
:file =\> nil  
map.connect “:controller/:action/edit/:file”,  
:mode =\> “edit”,  
:requirements =\> {:file =\> /._/},  
:file =\> nil

has done the work, and now everything seems to work well.

Once again, thank you very much for fast help.

Doug Barth wrote:

> What error are you getting in your Rails log file? If it’s a routing  
> error, you may need to specify that the :file portion of your route  
> can contain pretty much anything.
> 
> map.connect “:controller/:action/view/:file”, :requirements =\>  
> {:file =\> /.\*/}
> 
> –  
> Doug Barth
