Upcoming and OnDemand Webinars View full list

Apache Page Caching and Multiview

Charles Brian Quinn

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:

http://example.com/articles

Would correctly generate the page:

/path/to/app/public/articles.html

Subsequent visits would load the cached page.

However, if you then tried to visit a page like:

http://example.com/articles/2

Where a route used that for pagination, or simply any action off that resource, you apache would try and request a file like:

/path/to/app/public/articles.html/2.html

This is problematic, and does not work.

If, however, you removed the cached file and instead created the directory first, like so:

/path/to/app/public/articles/

When you requested the resource:

http://example.com/articles

it would correctly generate an index file:

/path/to/app/public/articles/index.html

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
</Location>

to this:

<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:

http://example.com/articles

Still generate the cached file:

/path/to/app/public/articles/index.html

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!

References

Not Happy with Your Current App, or Digital Product?

Submit your event

Let's Discuss Your Project

Let's Discuss Your Project