1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-01 20:30:39 +02:00

Closes #2596 - Enhancement to remove query strings from static resources.

This commit is contained in:
Cameron
2017-04-26 13:58:01 -07:00
parent 252abfdce6
commit 2724127ba2
3 changed files with 64 additions and 4 deletions

View File

@@ -42,6 +42,7 @@
<IfModule mod_env.c> <IfModule mod_env.c>
SetEnv HTTP_MOD_REWRITE On SetEnv HTTP_MOD_REWRITE On
SetEnv HTTP_MOD_REWRITE_MEDIA On SetEnv HTTP_MOD_REWRITE_MEDIA On
SetEnv HTTP_MOD_REWRITE_STATIC On
</IfModule> </IfModule>
### enable rewrites ### 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 ^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] 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 ### send 404 on missing files in these folders
RewriteCond %{REQUEST_URI} !^/(e107_images|e107_files)/ 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 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
</ifmodule> </ifmodule>
<FilesMatch "\.(js|css|ico|pdf|flv|jpg|jpeg|png|gif|swf|mp3|mp4)$">
Header set Cache-Control "public"
Header unset Cookie
Header unset Set-Cookie
</FilesMatch>
### Enable when developing locally. ### Enable when developing locally.
### SetEnv E_DEV true ### SetEnv E_DEV true

View File

@@ -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)); 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. // Define the domain name and subdomain name.
if(is_numeric(str_replace(".","",$_SERVER['HTTP_HOST']))) if(is_numeric(str_replace(".","",$_SERVER['HTTP_HOST'])))
{ {

View File

@@ -1255,7 +1255,8 @@ class e_jsmanager
$path = $path[1]; $path = $path[1];
if(strpos($path, 'http') !== 0) if(strpos($path, 'http') !== 0)
{ {
$path = $tp->replaceConstants($path, 'abs').'?external=1&amp;'.$this->getCacheId(); $path = $tp->replaceConstants($path, 'abs').'?external=1'; // &amp;'.$this->getCacheId();
$path = $this->url($path,'css');
} }
echo $pre.'<link rel="stylesheet" media="'.$media.'" type="text/css" href="'.$path.'" />'.$post; echo $pre.'<link rel="stylesheet" media="'.$media.'" type="text/css" href="'.$path.'" />'.$post;
@@ -1274,7 +1275,8 @@ class e_jsmanager
if($post) $post = "\n".$post; if($post) $post = "\n".$post;
$path = $path[0]; $path = $path[0];
$path = $tp->replaceConstants($path, 'abs').'?external=1&amp;'.$this->getCacheId(); $path = $tp->replaceConstants($path, 'abs').'?external=1'; // &amp;'.$this->getCacheId();
$path = $this->url($path,'js');
echo $pre.'<script type="text/javascript" src="'.$path.'"></script>'.$post; echo $pre.'<script type="text/javascript" src="'.$path.'"></script>'.$post;
echo "\n"; echo "\n";
continue; continue;
@@ -1325,7 +1327,8 @@ class e_jsmanager
{ {
continue; 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) elseif($this->isValidUrl($path) === false)
{ {
@@ -1365,7 +1368,8 @@ class e_jsmanager
if(!e107::getPref('e_jslib_nocombine')) continue; 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) 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 .= "&amp;".$this->getCacheId();
}
else
{
$path .= "?".$this->getCacheId();
}
return $path;
}
/** /**
* Check CDN Url is valid. * Check CDN Url is valid.
* Experimental. * Experimental.