# Page caching when name contains a dot (period)

**URL:** <https://www.ruby-forum.com/t/page-caching-when-name-contains-a-dot-period/102035>\
**Category:** Rails\
**Created:** [February 7, 2006, 2:29pm UTC](https://www.ruby-forum.com/t/page-caching-when-name-contains-a-dot-period/102035 "2006-02-07T14:29:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dnstevenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8dc957/32.png) [@dnstevenson](https://www.ruby-forum.com/u/dnstevenson)\
**Post date:** [February 7, 2006, 2:29pm UTC](https://www.ruby-forum.com/t/page-caching-when-name-contains-a-dot-period/102035/1 "2006-02-07T14:29:56Z")

</div>

Hi Everyone,

Just thought I’d post some details of an interesting little quirk I’ve  
found  
with page caching.

For a site I’ve just built for a small music festival, there are a  
number of  
artist profiles. I’m storing the artists in my database, but using  
caches\_page to speed things up when displaying the details to the  
public.

I’ve also made it so that instead of the numerical ID appearing in the  
URL, it  
uses the artist’s name instead. So if someone called “Bob S.” was  
playing, the URL would be: /artists/Bob+Smith

Now, with the page caching, it works fine for most of the artists, since  
Bob  
Smith’s cached page gets stored in myapp/public/artists/Bob+Smith.html

But what if “B. Smith” was playing - you’d expect it to generate  
“B.+Smith.html”, but it doesn’t, just a file called “B.+Smith” with no  
“.html”  
on the end of it. It seems the caching system does not add a file  
extension  
to a page name that already has a dot (period) in it.

The end result of this is that Apache (this is on Dreamhost, btw) fails  
to  
recognise that the cached page is HTML (since it has no extension) and  
serves  
the raw HTML as text/plain… not pretty!

Furthermore, you won’t notice this on the first page view, since at the  
point  
it generates the cached page using Rails, I guess it’s serving up the  
result  
from the Rails controller, rather than the newly generated cached page.

This problem only becomes apparent on the _second_ page view - and only  
then  
if you do a shift-reload forced refresh from the server to bypass your  
local  
browser’s cache.

I quickly tried renaming the problematic cache files and putting “.html”  
on  
the end of their names just to see if that helped, but then we’re back  
to  
square one - the cache thinks it’s the first time that page has been  
viewed,  
so a new file without a “.html” gets created (and works first time), and  
then  
you’re back to the raw HTML being served up as plain text on subsequent  
views.

So, the workaround for this is to (assuming all the pages that are being  
cached should be served as text/html) make a .htaccess file with the  
following line in it, and put it in the same directory as the  
problematic  
cached files:

ForceType text/html

That solves the problem and serves all the pages (even those without  
file  
extensions) as text/html - though whether this is a bigger issue (maybe  
even  
a slight bug) with caches\_page, I guess is up for debate.

Anyway, I thought I’d post my easy workaround in case anyone else finds  
themselves in the same situation. (Though surely I’m not the first one  
to  
encounter this?)

Cheers,

~Dave

–

Dave S.  
Rent-A-Monkey Website Development

> **[Tree Removal Service For Home & Businesses in Salt Lake City, UT](https://www.rentamonkey.com/)**
>
> Rent A Monkey Tree Service provides the safest, highest-quality tree removal for Salt Lake City, UT homes and businesses. Request a service today!

PGP Key: [http://www.rentamonkey.com/pgpkey.asc](http://www.rentamonkey.com/pgpkey.asc)

---

<div class="post-metadata">

**Author:** ![dnstevenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8dc957/32.png) [@dnstevenson](https://www.ruby-forum.com/u/dnstevenson)\
**Post date:** [April 15, 2010, 3:21am UTC](https://www.ruby-forum.com/t/page-caching-when-name-contains-a-dot-period/102035/2 "2010-04-15T03:21:16Z")

</div>

Dave S. wrote:

> So, the workaround for this is to (assuming all the pages that are being  
> cached should be served as text/html) make a .htaccess file with the  
> following line in it, and put it in the same directory as the  
> problematic  
> cached files:
> 
> ForceType text/html
> 
> That solves the problem and serves all the pages (even those without  
> file  
> extensions) as text/html - though whether this is a bigger issue (maybe  
> even  
> a slight bug) with caches\_page, I guess is up for debate.
> 
> Anyway, I thought I’d post my easy workaround in case anyone else finds  
> themselves in the same situation. (Though surely I’m not the first one  
> to  
> encounter this?)

I can’t be sure whether you are the first, but you certainly weren’t the  
last. Thanks for this. I ended up putting that directive in the overall  
apache2 config file, instead of using the .htaccess, because then  
manually removing the cache doesn’t remove the solution.

Thanks,  
ben
