# Different page caching folder for different domains

**URL:** <https://www.ruby-forum.com/t/different-page-caching-folder-for-different-domains/163787>\
**Category:** Rails\
**Created:** [March 24, 2009, 10:07pm UTC](https://www.ruby-forum.com/t/different-page-caching-folder-for-different-domains/163787 "2009-03-24T22:07:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fipa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9e8a1a/32.png) [@fipa](https://www.ruby-forum.com/u/fipa)\
**Post date:** [March 24, 2009, 10:07pm UTC](https://www.ruby-forum.com/t/different-page-caching-folder-for-different-domains/163787/1 "2009-03-24T22:07:46Z")

</div>

Hi,

I created a multi-domain application, and I wanted to add page caching,  
how can I tell Rails that it should save each cached page under a  
subfolder such as public/www.mysite1.com/ and public/www.mysite2.com

---

<div class="post-metadata">

**Author:** ![fipa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9e8a1a/32.png) [@fipa](https://www.ruby-forum.com/u/fipa)\
**Post date:** [March 27, 2009, 8:34am UTC](https://www.ruby-forum.com/t/different-page-caching-folder-for-different-domains/163787/2 "2009-03-27T08:34:51Z")

</div>

On Tue, Mar 24, 2009 at 2:07 PM, Fernando P. \<  
removed\_email\_address@domain.invalid\> wrote:

> Hi,
> 
> I created a multi-domain application, and I wanted to add page caching,  
> how can I tell Rails that it should save each cached page under a  
> subfolder such as public/www.mysite1.com/ and public/www.mysite2.com

If you’re using page caching, then the cached page should located  
relative  
to  
the root of your website. Thus, if you were to access the index page on  
both  
[www.mysite1.com](http://www.mysite1.com) and [www.mysite2.com](http://www.mysite2.com), the you should be able to find an  
index.html in the following locations:

URL: [www.mysite1.com/index.html](http://www.mysite1.com/index.html) On Disk:  
/rails-app1/public/index.html  
URL: [www.mysite2.com/index.html](http://www.mysite2.com/index.html) On Disk:  
/rails-app2/public/index.html

Now, if you really want to change the location of the cached pages to  
use  
another  
directory other than the above, you can do the following:

Moving your Page Cache

First you’d want to add the following to your _/config/environment.rb_:

config.action\_controller.page\_cache\_directory = RAILS\_ROOT +  
“/public/cache/”

This tells Rails to publish all your cached files in the /public/cache  
directory. You would then want to change your Rewrite rules in your \*  
httpd.conf\* to be:

12345

# Rewrite index to check for static RewriteRule ^/$

cache/index.html [QSA] # Rewrite to check for Rails cached page  
RewriteRule ^([^.]+)$ cache/$1.html [QSA]

If you would like to learn more about the wonderful world of caching, I  
would recommend reading the following:

[http://railslab.newrelic.com/](http://railslab.newrelic.com/)

Good luck,

-Conrad
