mirror of
https://github.com/e107inc/e107.git
synced 2025-08-05 14:17:49 +02:00
Closes #2596 - Enhancement to remove query strings from static resources.
This commit is contained in:
@@ -42,6 +42,7 @@
|
||||
<IfModule mod_env.c>
|
||||
SetEnv HTTP_MOD_REWRITE On
|
||||
SetEnv HTTP_MOD_REWRITE_MEDIA On
|
||||
SetEnv HTTP_MOD_REWRITE_STATIC On
|
||||
</IfModule>
|
||||
|
||||
### 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
|
||||
</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.
|
||||
### SetEnv E_DEV true
|
||||
|
@@ -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'])))
|
||||
{
|
||||
|
@@ -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.'<link rel="stylesheet" media="'.$media.'" type="text/css" href="'.$path.'" />'.$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.'<script type="text/javascript" src="'.$path.'"></script>'.$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.
|
||||
|
Reference in New Issue
Block a user