-
Notifications
You must be signed in to change notification settings - Fork 20
Static cache setup
Follow these steps to setup static caching:
-
Create a cache directory (e.g. 'static_cache') in your public webroot and CHMOD to 777 (or CHOWN to the user PHP runs as).
-
Set
stash_static_basepath
to the full path of your newly created cache directory in your config. Stash will read and write to this directory so be very careful to specify the correct path, especially if your PHP installation can write anywhere in your filesystem (e.g. MAMP). -
Set
stash_static_url
to the absolute or root-relative URL of the cache directory in your config. -
Set
stash_static_cache_enabled
to TRUE in your config. -
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 number of your site. If you are using MSM, create an .htaccess file for each site and save it in the site's directory.
<IfModule mod_rewrite.c>
RewriteEngine on
#################################################################################
# START STASH STATIC CACHE
# Exclude image files
RewriteCond $1 !\.(gif|jpe?g|png|ico)$ [NC]
# We only want GET requests
RewriteCond %{REQUEST_METHOD} GET
# Exclude CSS/ACT EE URLs and 'preview'
RewriteCond %{QUERY_STRING} !^(css|ACT|URL|preview)
# Uncomment this if you want to disable static caching for logged-in users
#RewriteCond %{HTTP_COOKIE} !exp_sessionid [NC]
# Remove index.php from conditions
RewriteCond $1 ^(index.php/)*(.*)(/*)$
# Check if cached index.html exists
RewriteCond %{DOCUMENT_ROOT}/static_cache/[site_id]/$2/index.html (.*\.(.*))$
RewriteCond %1 -f
# Rewrite to the cached page
RewriteRule ^(index.php/*)*(.*)(/*) /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>
Getting started
Using Stash
Using Mustash
- Mustash
- Installing Mustash
- Managing variables
- Managing bundles
- Cache-breaking rules
- Mustash plugins
- Mustash Varnish plugin
- Mustash plugin development
- Mustash API
Template design patterns
Tag reference
- {exp:stash:set}
- {exp:stash:get}
- {exp:stash:block}
- {exp:stash:set_value}
- {exp:stash:append}
- {exp:stash:append_value}
- {exp:stash:prepend}
- {exp:stash:prepend_value}
- {exp:stash:copy}
- {exp:stash:context}
- {exp:stash:is_empty}
- {exp:stash:not_empty}
- {exp:stash:set_list}
- {exp:stash:get_list}
- {exp:stash:append_list}
- {exp:stash:prepend_list}
- {exp:stash:split_list}
- {exp:stash:join_lists}
- {exp:stash:list_count}
- {exp:stash:unset}
- {exp:stash:flush_cache}
- {exp:stash:bundle}
- {stash:embed}
- {exp:stash:extend}
- {exp:stash:parse}
- {exp:stash:cache}
- {exp:stash:static}
- {exp:stash:finish}
- {exp:stash:not_found}
- Short tag syntax
- Using Stash methods in your own add-ons