REST + Caching + Apache 2.2 Rewrite problem and solution?

30 views
Skip to first unread message

Nauhaie None

unread,
Aug 31, 2006, 12:36:06 PM8/31/06
to rubyonra...@googlegroups.com
Hi,

A lot of us are now using Apache 2.2 + mod_rewrite to forward incoming
and uncached requests to a Mongrel Cluster.

That was fine until REST arrived.

With the current recommended configuration, Apache works as follows:

a. There is a static file avaliable in the file system => send it
(regardless to the request method)
b. There is none, forward request to Mongrel Cluster

However, with RESTful Rails, we have urls such as /articles/1 which
should be cached only when we GET it, not when we POST or PUT it. What
if we want to update an article and Apache sends us the static HTML file
instead of forwarding our request to Rails?

Here is the solution I suggest:

Replace in apache configuration file:

# Redirect all non-static requests to cluster
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://MyCluster%{REQUEST_URI} [P,QSA,L]

By

# Redirect all non-static requests to cluster
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_METHOD} !^GET*
RewriteRule ^/(.*)$ balancer://MyCluster%{REQUEST_URI} [P,QSA,L]

What do you thing about that?

--
Posted via http://www.ruby-forum.com/.

Rick Olson

unread,
Aug 31, 2006, 5:06:41 PM8/31/06
to rubyonra...@googlegroups.com
> Replace in apache configuration file:
>
> # Redirect all non-static requests to cluster
> RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
> RewriteRule ^/(.*)$ balancer://MyCluster%{REQUEST_URI} [P,QSA,L]
>
> By
>
> # Redirect all non-static requests to cluster
> RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f [OR]
> RewriteCond %{REQUEST_METHOD} !^GET*
> RewriteRule ^/(.*)$ balancer://MyCluster%{REQUEST_URI} [P,QSA,L]
>
> What do you thing about that?
>

Does it work? Seems like it should. Mongrel has something similar
built in actually (not that it'll help in this case).

--
Rick Olson
http://weblog.techno-weenie.net
http://mephistoblog.com

Reply all
Reply to author
Forward
0 new messages