# WPP Cache load start

set $wpp_cache 1;
set $wpp_mobile 1;
set $wpp_amp 1;

if ($request_method = POST){
	set $wpp_cache 0;
}

if ($is_args) {
	set $wpp_cache 0;
}

if (-f "$document_root/.maintenance") {
	set $wpp_cache 0;
}

if ($http_cookie ~* (wordpress_logged_in_|wp\-postpass_|wptouch_switch_toggle|comment_author_|comment_author_email_)) {
	set $wpp_cache 0;
}

if (!-f "{CACHEDIR}$http_host/$request_uri/index.html") {
	set $wpp_cache 0;
}

if (!-f "{CACHEDIR}$http_host/$request_uri/index.html_mobile") {
	set $wpp_mobile 0;
}

{USER_AGENTS}

if ($http_user_agent ~* (Mobile|Android|Kindle|BlackBerry|Opera+Mini|Opera+Mobi)) {
      set $wpp_cache "{$wpp_cache}{$wpp_mobile}";
}

if ($request_uri ~* /{AMP_TAG}/$) {
	set $wpp_cache "{$wpp_cache}{$wpp_mobile}{$wpp_amp}";
}

if ($wpp_cache = 111){
    rewrite .* /{CONTENT_DIR}/cache/{CACHEDIR_BASENAME}/$http_host/$request_uri/index.html_mobile_amp last;
}

if ($wpp_cache = 101){
    rewrite .* /{CONTENT_DIR}/cache/{CACHEDIR_BASENAME}/$http_host/$request_uri/index.html_amp last;
}

if ($wpp_cache = 11){
    rewrite .* /{CONTENT_DIR}/cache/{CACHEDIR_BASENAME}/$http_host/$request_uri/index.html_mobile last;
}

if ($wpp_cache = 1){
    rewrite .* /{CONTENT_DIR}/cache/{CACHEDIR_BASENAME}/$http_host/$request_uri/index.html last;
}

# WPP Cache load end