It’s all about the Rewrite Condition.
Rails
page caching is great and
REST is great, but together they can be confusing. Considering a resource “Posts”, Rails gives you the following routes:
GET /posts {:controller=>"posts", :action=>"index"}
POST /posts {:controller=>"posts", :action=>"create"}
PUT /posts/:id {:controller=>"posts", :action=>"update"}
If you have Apache configured with mod_rewrite to serve your cached pages (instead of sending them to mongrel, e.g.), then all of those routes appear to be requests for “posts.html”. The end result is that you can’t create or update the “Posts” resource.
The solution, let Apache handle the
GET requests and mongrel handle everything else:
RewriteEngine On
RewriteRule ^/$ /index.html [QSA]
RewriteCond %{REQUEST_METHOD} ^GET$
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://mongrel_cluster%{REQUEST_URI} [P,QSA,L]