Skip to content

Static cache setup

Mark Croxton edited this page Jun 25, 2013 · 23 revisions

Follow these steps to setup static caching:

  1. Create a cache directory (e.g. 'static_cache') in your public webroot and CHMOD to 777 (or CHOWN to the user PHP runs as).

  2. Set stash_static_basepath to the full path of your newly created cache directory in your config.

  3. Set stash_static_url to the absolute or root-relative URL of the cache directory in your config.

  4. Set stash_static_cache_enabled to TRUE in your config.

  5. If you are using Mustash, visit the 'Stash cache rewrite rules' page in Settings to view an auto-generated htaccess file that you can copy and paste into your public webroot. Alternatively, edit the .htaccess file below with the path and url to your static cache directory, and save it in your public webroot. Replace '[site_id]' with the id of your site. If you are using MSM, create an .htaccess file for each site and save it in the site's directory.

.htaccess file

<IfModule mod_rewrite.c>
 
RewriteEngine on    

#################################################################################
# START STASH STATIC CACHE

# Exclude POST requests
RewriteCond %{REQUEST_METHOD} !=POST

# Exclude CSS/ACT EE URLs
RewriteCond %{QUERY_STRING} !^(css|ACT|URL)

# Remove index.php from conditions
RewriteCond $1 ^(index.php/)*(.*)(/*)$

# Check if cached index.html exists
RewriteCond /path/to/static_cache/[site_id]/$2/index.html (.*\.(.*))$
RewriteCond %1 -f

# Rewrite to the cached page
RewriteRule ^(index.php/*)*(.*)(/*) http://www.my-site.com/static_cache/[site_id]/$2/index.%2 [L]

# END STASH STATIC CACHE RULES
#################################################################################

# -------------------------------------------------------------------------------
# Officially supported method to remove index.php from ExpressionEngine URLs
# See: http://ellislab.com/expressionengine/user-guide/urls/remove_index.php.html
# -------------------------------------------------------------------------------

RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

</IfModule>
Clone this wiki locally