Skip to content

Instantly share code, notes, and snippets.

@schowdhury
Created March 22, 2011 14:58
Show Gist options
  • Save schowdhury/881346 to your computer and use it in GitHub Desktop.
Save schowdhury/881346 to your computer and use it in GitHub Desktop.
rails caching with apache enable through rewrite rules
I generate all my page caching in public/cache directory. The following apache rewrite rules check cache before hitting the rails app
<VirtualHost *:80>
RewriteEngine On
RewriteCond %{THE_REQUEST} ^(GET|HEAD)
RewriteCond %{REQUEST_URI} ^/([^.]+)$
RewriteCond %{DOCUMENT_ROOT}/cache/%1.html -f
RewriteRule ^/[^.]+$ /cache/%1.html [QSA,L]
RewriteCond %{THE_REQUEST} ^(GET|HEAD)
RewriteCond %{DOCUMENT_ROOT}/cache/index.html -f
RewriteRule ^/$ /cache/index.html [QSA,L]
ServerName myserver.com
DocumentRoot /var/www/rails/myproject/current/public
PassengerEnabled off
ProxyPass / http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/
</VirtualHost>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment