Blogs from the Ranch

< Back to Our Blog

Apache Page Caching and Multiview

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.

The Problem

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 Solution

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

to this:

<Location />
Options All FollowSymLinks -Indexes

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:

http://example.com/articles/ http://example.com/articles/2

Now correctly generate a folder with an index.html and 2.html, which caches just fine.

I hope this helps someone else out!


Not Happy with Your Current App, or Digital Product?

Submit your event

Let's Discuss Your Project

Let's Discuss Your Project