Skip to content

Instantly share code, notes, and snippets.

@bwiggs
Created July 19, 2012 02:21
Show Gist options
  • Save bwiggs/3140348 to your computer and use it in GitHub Desktop.
Save bwiggs/3140348 to your computer and use it in GitHub Desktop.
CakePHP Filename Cache Busting
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)\.(\d+)\.(js|css|png|jpg|gif)$ $1.$3 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
<?php
class AppHelper extends Helper {
/**
* Override so that the timestamp is added to the file instead of as a query parameter,
*/
public function assetTimestamp($path) {
$parts = explode('?', parent::assetTimestamp($path));
return substr_replace($parts[0], '.'.$parts[1], strrpos($parts[0],'.'), 0);
}
}
@RomsWebDesign
Copy link

Hi,

I have test your gist with the lastest CakePHP and it dosn't seems to work.
Can you help me please ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment