I just wanted to post a quick note to anyone searching for problems with Rails Page Caching with Apache.
We just helped a client through a tricky issue that manifested itself through some strangely generated cached files.
A visit to the resource:
Would correctly generate the page:
Subsequent visits would load the cached page.
However, if you then tried to visit a page like:
Where a route used that for pagination, or simply any action off that resource, you apache would try and request a file like:
This is problematic, and does not work.
If, however, you removed the cached file and instead created the directory first, like so:
When you requested the resource:
it would correctly generate an index file:
And then correctly generate any cached pages inside the directory like 2.html, 3.html for pagination (if setup in rails routes correctly).
The problem was that Apache has the MultiViews option turned on.
We changed the server configuration file from this:
<Location /> Options All FollowSymLinks MultiViews -Indexes </Location>
<Location /> Options All FollowSymLinks -Indexes </Location>
When you remove this option from the configuration, you get the correct caching behavior, which is that requests to:
Still generate the cached file:
But now, requests to the slash-ending url and resources off that route:
Now correctly generate a folder with an index.html and 2.html, which caches just fine.
I hope this helps someone else out!
Interested in learning more about our basic and advanced Back-End Courses?
Learn from the experts at a Big Nerd Ranch Bootcamp!
Interested in leveling up your coding skills from the same authors of the Big Nerd Ranch Guide? Subscribe to The Frontier today!