Skip to content

Instantly share code, notes, and snippets.

@lukecav
Last active March 31, 2020 08:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukecav/5607abcc9f33da97aabcffb195c2738f to your computer and use it in GitHub Desktop.
Save lukecav/5607abcc9f33da97aabcffb195c2738f to your computer and use it in GitHub Desktop.
Cache Enabler - .htaccess file example
# BEGIN Cache Enabler
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# set blog sub path
SetEnvIf Request_URI "^(.*)$" SUB_PATH=/wp-content/cache/cache-enabler/
# set Cache Enabler path
SetEnvIf Request_URI "^(.*)$" CE_PATH=$1
SetEnvIf Request_URI "^(/)index.php$" CE_PATH=$1
<IfModule mod_mime.c>
# webp HTML file
RewriteCond %{ENV:CE_PATH} /$
RewriteCond %{ENV:CE_PATH} !^/wp-admin/.*
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} =""
RewriteCond %{HTTP_COOKIE} !(wp-postpass|wordpress_logged_in|comment_author)_
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{HTTP:Accept} image/webp
RewriteCond %{DOCUMENT_ROOT}%{ENV:SUB_PATH}%{HTTP_HOST}%{ENV:CE_PATH}index-webp.html.gz -f
RewriteRule ^(.*) %{ENV:SUB_PATH}%{HTTP_HOST}%{ENV:CE_PATH}index-webp.html.gz [L]
# gzip HTML file
RewriteCond %{ENV:CE_PATH} /$
RewriteCond %{ENV:CE_PATH} !^/wp-admin/.*
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} =""
RewriteCond %{HTTP_COOKIE} !(wp-postpass|wordpress_logged_in|comment_author)_
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{DOCUMENT_ROOT}%{ENV:SUB_PATH}%{HTTP_HOST}%{ENV:CE_PATH}index.html.gz -f
RewriteRule ^(.*) %{ENV:SUB_PATH}%{HTTP_HOST}%{ENV:CE_PATH}index.html.gz [L]
AddType text/html .gz
AddEncoding gzip .gz
</IfModule>
# webp HTML file
RewriteCond %{ENV:CE_PATH} /$
RewriteCond %{ENV:CE_PATH} !^/wp-admin/.*
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} =""
RewriteCond %{HTTP_COOKIE} !(wp-postpass|wordpress_logged_in|comment_author)_
RewriteCond %{HTTP:Accept} image/webp
RewriteCond %{DOCUMENT_ROOT}%{ENV:SUB_PATH}%{HTTP_HOST}%{ENV:CE_PATH}index-webp.html -f
RewriteRule ^(.*) %{ENV:SUB_PATH}%{HTTP_HOST}%{ENV:CE_PATH}index-webp.html [L]
# default HTML file
RewriteCond %{ENV:CE_PATH} /$
RewriteCond %{ENV:CE_PATH} !^/wp-admin/.*
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} =""
RewriteCond %{HTTP_COOKIE} !(wp-postpass|wordpress_logged_in|comment_author)_
RewriteCond %{DOCUMENT_ROOT}%{ENV:SUB_PATH}%{HTTP_HOST}%{ENV:CE_PATH}index.html -f
RewriteRule ^(.*) %{ENV:SUB_PATH}%{HTTP_HOST}%{ENV:CE_PATH}index.html [L]
# wp override
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [END]
</IfModule>
# END Cache Enabler
@lukecav
Copy link
Author

lukecav commented Nov 1, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment