| @@ -28,13 +28,24 @@ | ||
| 28 | 28 | |
| 29 | 29 | $fallback_target = preg_replace( '/(.*)_(?:[a-z0-9]{32})\.(js|css)$/', '${1}_fallback.${2}', $original_request ); |
| 30 | 30 | $ao_cache_dir = '<!--ao-cache-dir-->'; |
| 31 | 31 | $js_or_css = pathinfo( $original_request, PATHINFO_EXTENSION ); |
| 32 | -$fallback_path = $ao_cache_dir . $js_or_css . '/autoptimize_fallback.' . $js_or_css; | |
| 33 | 32 | |
| 34 | -if ( $original_request !== $fallback_target && file_exists( $fallback_path ) ) { | |
| 33 | +// add multisite logic. | |
| 34 | +$multisite = false; | |
| 35 | +if ( true === $multisite ) { | |
| 36 | + preg_match( '#\/([0-9]{1,5})\/(?:js|css)\/[a-z0-9]*_fallback\.(?:js|css)$#', $fallback_target, $child_site_id ); | |
| 37 | + $ao_root_cache_dir = preg_replace( '#[0-9]*\/$#', '', $ao_cache_dir ); | |
| 38 | + $ao_cache_dir = $ao_root_cache_dir . $child_site_id[1] . '/'; | |
| 39 | +} | |
| 40 | + | |
| 41 | +$fallback_path = $ao_cache_dir . $js_or_css . '/<!--ao-cachefile-prefix-->fallback.' . $js_or_css; | |
| 42 | + | |
| 43 | +if ( strpos( $fallback_target, '//' ) === 0 || strpos( $fallback_target, '/' ) !== 0 ) { | |
| 44 | + exit(); | |
| 45 | +} else if ( $original_request !== $fallback_target && file_exists( $fallback_path ) ) { | |
| 35 | 46 | // error_log( 'Autoptimize file ' . $original_request . ' not found, using fallback instead.' ); |
| 36 | - header( 'HTTP/1.1 301 Moved Permanently' ); | |
| 47 | + header( 'HTTP/1.1 302 Found' ); | |
| 37 | 48 | header( 'Location: ' . $fallback_target ); |
| 38 | 49 | } else { |
| 39 | 50 | // error_log( 'Autoptimize file ' . $original_request . ' not found, sending 410 gone response.' ); |
| 40 | 51 | header( 'HTTP/1.1 410 Gone' ); |