Created
December 11, 2019 21:54
-
-
Save joeyblake/898fb40ed89609cf9fa1ff9be9c4a3c3 to your computer and use it in GitHub Desktop.
WordPress cache enabler plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# BEGIN Cache Enabler | |
# | |
# This version is meant for Apache 2.3.9 or later. | |
# | |
# Reference: https://www.keycdn.com/support/wordpress-cache-enabler-plugin#apache | |
<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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment