Skip to content

Instantly share code, notes, and snippets.

@NerdOfLinux
Last active November 12, 2020 04:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NerdOfLinux/507f5bc537562e51f21c300dcc1bcdec to your computer and use it in GitHub Desktop.
Save NerdOfLinux/507f5bc537562e51f21c300dcc1bcdec to your computer and use it in GitHub Desktop.
WP Super Cache NGINX rules without changing the location block
# Based heavily off W3 Total Cache NGINX rules and WP Super Cache on https://codex.wordpress.org/Nginx
set $w3tc_rewrite 1;
if ($request_method = POST) {
set $w3tc_rewrite 0;
}
if ($query_string != "") {
set $w3tc_rewrite 0;
}
if ($request_uri !~ \/$) {
set $w3tc_rewrite 0;
}
if ($http_cookie ~* "(comment_author|wp\-postpass|w3tc_logged_out|wordpress_logged_in|wptouch_switch_toggle)") {
set $w3tc_rewrite 0;
set $cache_status BYPASS;
}
set $w3tc_ssl "";
if ($scheme = https) {
set $w3tc_ssl -https;
}
if ($http_x_forwarded_proto = 'https') {
set $w3tc_ssl -https;
}
set $w3tc_ext "";
if (-f "$document_root/wp-content/cache/supercache/$http_host/$request_uri/index$w3tc_ssl.html") {
set $w3tc_ext .html;
}
if ($w3tc_ext = "") {
set $w3tc_rewrite 0;
}
if ($w3tc_rewrite = 1) {
rewrite .* "/wp-content/cache/supercache/$http_host/$request_uri/index$w3tc_ssl$w3tc_ext" last;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment