RewriteRule Proxying from Subdirectory to Root

Discuss practical ways rearrange URLs using mod_rewrite.

RewriteRule Proxying from Subdirectory to Root

Postby BigglesZX » Wed Jul 01, 2009 4:33 am

Hi all,

I'm trying to use mod_rewrite to proxy requests from my main Apache server to a Mongrel server running my Ruby on Rails application.

My main server is http://lab.mydomain.com and I want users to be able to access the application at http://lab.mydomain.com/myapp/, but have those requests transparently proxied to http://localhost:8080/ (the mongrel server running on the same machine as Apache).

At the moment my rewrite rules look like this (in .htaccess in the /myapp/ dir):

Code: Select all
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /myapp/
RewriteRule (.*) http://localhost:8080/$1 [P]
</IfModule>


However, there is a problem. URLs in the application are all absolute and start with "/", because in the testing phase the application ran out of the root directory. This means that the index page of the application will load, but stuff like images and stylesheets won't, because they are using URLs like "/images/myimage.jpg" and "/stylesheets/style.css".

My question is: is there a way I can address this using mod_rewrite, or should I instead look to correct those URLs in the application to use relative paths instead (via some Rails configuration, rather than mod_rewrite)? I'm thinking this may be beyond the scope of mod_rewrite since it's the application that is causing stuff like http://lab.mydomain.com/images/myimage.jpg to be requested rather than http://lab.mydomain.com/myapp/images/myimage.jpg, which is being rewritten.

Any help would be hugely appreciated. Thanks for reading!

Biggs
BigglesZX
 
Posts: 2
Joined: Wed Jul 01, 2009 4:24 am

Postby richardk » Wed Jul 01, 2009 8:33 am

You should edit the application. You could create a base path variable (if there isn't one already).
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby BigglesZX » Wed Jul 01, 2009 8:39 am

Hi richardk,

Thanks for your reply. I have reached very much the same conclusion. Thanks for your time in reading my post in any case!

Biggs
BigglesZX
 
Posts: 2
Joined: Wed Jul 01, 2009 4:24 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 22 guests

cron