# Apache Rewrites in VirtualHost Changing Rails Base URL?

**URL:** <https://www.ruby-forum.com/t/apache-rewrites-in-virtualhost-changing-rails-base-url/121791>\
**Category:** Rails\
**Created:** [November 30, 2007, 10:06pm UTC](https://www.ruby-forum.com/t/apache-rewrites-in-virtualhost-changing-rails-base-url/121791 "2007-11-30T22:06:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ian\_Lesperance](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/71c47a/32.png) [@Ian\_Lesperance](https://www.ruby-forum.com/u/Ian_Lesperance)\
**Post date:** [November 30, 2007, 10:06pm UTC](https://www.ruby-forum.com/t/apache-rewrites-in-virtualhost-changing-rails-base-url/121791/1 "2007-11-30T22:06:51Z")

</div>

I’m trying to configure my Rails application to handle most requests  
using Mongrel with a select few (file uploads and other long-running  
processes) passed through to the CGI dispatcher.

Here is what my Apache configuration (httpd.conf) looks like:

```
<virtualhost example.com>
...
# Long-running processes
RewriteCond %{REQUEST_URI} ^/lorem/ipsum.*$
RewriteRule ^(.*)$ /dispatch.cgi [QSA,L]

# Redirect all non-static requests to cluster
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ balancer://mongrel_cluster%{REQUEST_URI}

```

[P,QSA,L]  
SetEnv force-proxy-request-1.0 1  
SetEnv proxy-nokeepalive 1

What I find is that a request to /lorem/ipsum is properly passed  
through to the CGI dispatcher, but that request is processed as if it  
were merely /. As such, it always processes the main page of my  
application instead of /lorem/ipsum. All the URLs in the source are  
also prefixed with /lorem/ipsum, including linked media such as  
stylesheets and javascripts, which makes me think it’s treating /lorem/  
ipsum as if it were the RewriteBase.

It’s probably worth noting that I’ve tried using CGI from inside  
the .htaccess configuration, and this never happened. But in order to  
make my .htaccess file environment-independent, it’d be much easier to  
keep the rewrites inside httpd.conf (since that’s where the proxy  
redirect is), so each environment can be customized as necessary  
without some overly elaborate deployment/configuration scheme.

Is there something about my Apache rewrites that is causing Rails to  
misinterpret the request URL and treat it as / instead of /lorem/  
ipsum? Why else might Rails be treating the URL differently in CGI  
versus Mongrel?
