Search

Apache Page Caching and Multiview

Charles Brian Quinn

2 min read

Aug 3, 2009

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:

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

Josh Justice

Reviewer Big Nerd Ranch

Josh Justice has worked as a developer since 2004 across backend, frontend, and native mobile platforms. Josh values creating maintainable systems via testing, refactoring, and evolutionary design, and mentoring others to do the same. He currently serves as the Web Platform Lead at Big Nerd Ranch.

Speak with a nerd

Schedule a call today! Our team of nerds are ready to help

Let's Talk

Related Posts

We are ready to discuss your needs.

Stay in Touch WITH Big Nerd Ranch News