diff --git a/e107.htaccess b/e107.htaccess index a2d147762..8e45d5a32 100644 --- a/e107.htaccess +++ b/e107.htaccess @@ -42,6 +42,7 @@ SetEnv HTTP_MOD_REWRITE On SetEnv HTTP_MOD_REWRITE_MEDIA On + SetEnv HTTP_MOD_REWRITE_STATIC On ### enable rewrites @@ -65,6 +66,9 @@ RewriteRule ^media\/img\/([-A-Za-z0-9+/]*={0,3})\.(jpg|gif|png)?$ thumb.php?id=$1 [NC,L] ReWriteRule ^theme\/img\/(a)?([\d]*)x(a)?([\d]*)\/(.*)?$ thumb.php?src=e_THEME/$5&$1w=$2&$3h=$4 [NC,L] +### Rewrite for Static Scripts + ReWriteRule ^static\/[0-9]*\/(.*)$ $1 [NC,L] + ### send 404 on missing files in these folders RewriteCond %{REQUEST_URI} !^/(e107_images|e107_files)/ @@ -99,6 +103,12 @@ AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css text/javascript application/x-javascript application/javascript application/xml text/xml application/rss+xml + + Header set Cache-Control "public" + Header unset Cookie + Header unset Set-Cookie + + ### Enable when developing locally. ### SetEnv E_DEV true diff --git a/e107_handlers/e107_class.php b/e107_handlers/e107_class.php index 047c7e86b..d7f012f5d 100644 --- a/e107_handlers/e107_class.php +++ b/e107_handlers/e107_class.php @@ -3889,6 +3889,11 @@ class e107 define('e_MOD_REWRITE_MEDIA', (getenv('HTTP_MOD_REWRITE_MEDIA')=='On' || getenv('REDIRECT_HTTP_MOD_REWRITE_MEDIA')=='On' ? true : false)); } + if(!defined('e_MOD_REWRITE_STATIC')) // Allow e107_config.php to override. + { + define('e_MOD_REWRITE_STATIC', (getenv('HTTP_MOD_REWRITE_STATIC')=='On' || getenv('REDIRECT_HTTP_MOD_REWRITE_STATIC')=='On' ? true : false)); + } + // Define the domain name and subdomain name. if(is_numeric(str_replace(".","",$_SERVER['HTTP_HOST']))) { diff --git a/e107_handlers/js_manager.php b/e107_handlers/js_manager.php index be33dfcc0..1f2915698 100644 --- a/e107_handlers/js_manager.php +++ b/e107_handlers/js_manager.php @@ -1255,7 +1255,8 @@ class e_jsmanager $path = $path[1]; if(strpos($path, 'http') !== 0) { - $path = $tp->replaceConstants($path, 'abs').'?external=1&'.$this->getCacheId(); + $path = $tp->replaceConstants($path, 'abs').'?external=1'; // &'.$this->getCacheId(); + $path = $this->url($path,'css'); } echo $pre.''.$post; @@ -1274,7 +1275,8 @@ class e_jsmanager if($post) $post = "\n".$post; $path = $path[0]; - $path = $tp->replaceConstants($path, 'abs').'?external=1&'.$this->getCacheId(); + $path = $tp->replaceConstants($path, 'abs').'?external=1'; // &'.$this->getCacheId(); + $path = $this->url($path,'js'); echo $pre.''.$post; echo "\n"; continue; @@ -1325,7 +1327,8 @@ class e_jsmanager { continue; } - $path = $tp->replaceConstants($path, 'abs').'?'.$this->getCacheId(); + $path = $tp->replaceConstants($path, 'abs'); // .'?'.$this->getCacheId(); + $path = $this->url($path, 'css'); } elseif($this->isValidUrl($path) === false) { @@ -1365,7 +1368,8 @@ class e_jsmanager if(!e107::getPref('e_jslib_nocombine')) continue; } - $path = $tp->replaceConstants($path, 'abs').'?'.$this->getCacheId(); + $path = $tp->replaceConstants($path, 'abs'); //.'?'.$this->getCacheId(); + $path = $this->url($path, 'js'); } if($isExternal === true && $this->isValidUrl($path) == false) @@ -1396,6 +1400,47 @@ class e_jsmanager } + + private function url($path,$type) + { + if(e_MOD_REWRITE_STATIC === true && $this->isInAdmin() !== true) + { + $base = 'static/'; + + $srch = array( + e_PLUGIN_ABS, + e_THEME_ABS, + e_WEB_ABS + ); + + + $repl = array( + e_HTTP.$base.$this->getCacheId().'/'.e107::getFolder('plugins'), + e_HTTP.$base.$this->getCacheId().'/'.e107::getFolder('themes'), + e_HTTP.$base.$this->getCacheId().'/'.e107::getFolder('web') + ); + + $folder = str_replace($srch,$repl,$path); + + return trim($folder); + } + + + if(strpos($path,'?')!==false) + { + $path .= "&".$this->getCacheId(); + } + else + { + $path .= "?".$this->getCacheId(); + } + + return $path; + + } + + + /** * Check CDN Url is valid. * Experimental.