.htaccess - htaccess URL fingerprinting -


is there way use mod_rewrite , htaccess implement url fingerprinting without having change file names every update?

this file structure on server (irrelevant files omitted):

/apps     /foo         /public             /js                 file1.min.js                 file2.min.js             /css                 file1.css                 file2.css     /bar         /public             /js                 file1.min.js                 file2.min.js             /css                 file1.css                 file2.css 

my pages in application folders. <script> elements in pages @ moment:

<script src='public/js/file1.min.js'></script> <script src='public/js/file2.min.js'></script> 

i'd implement url fingerprinting elements this:

<script src='public/js/file1.1a516fba.min.js' integrity='sha384-...'></script> <script src='public/js/file2.faf315f3.min.js' integrity='sha384-...'></script> 

i deploy every time file names changed wondering if there easier way.

i tried in .htaccess file inside apps:

<ifmodule mod_rewrite.c> rewriteengine on rewriterule ^public/(css|js)/(.*)\.[0-9]+(\.css|\.js)$ /public/$1/$2.$3 [l, qsa] </ifmodule> 

this did not work. tried variations of , either ended http 500 (completely failed) or 404 (rules did not work).

i'd avoid repeating .htaccess in every application's folder if possible, , i'd keep file in source control (so inside /apps).

you trying capture faf315f3 allowing digits - problem lies. need include alphas well:

rewriterule ^public/(css|js)/([^.]+).[0-9a-z]+((?:.min)?.(?:css|js))$ /public/$1/$2$3 [nc,qsa,l] 

additionally, i've made few enhancements rule:

  1. you need not escape periods in rules - these needed in conditions.
  2. use [^.]+ (anything not period) instead of .* (anything, zero-length , up) second capture-group.
  3. move period outside of last css|js capture capturing duplicate in destination uri.
  4. capture entire group file extension, , make .min optional. means removing period in destination uri, resulting in $1/$2$3.

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -