Rewrite rule for .123456.js name in htaccess

I have this file on my web server:

http://example.com/static/js/min/common.min.js

Since all the files inside /static/are cached using CloudFlare Edge Cache, I need a way to change the URL with something similar, so if the file is changed, the new version will be automatically updated:

http://example.com/static/js/min/common.min.1234567890.js

Where 1234567890 is the timestamp for changing the file date. I am already creating the file name according to the date of change, the problem I encountered is in the .htaccess file.

This works great:

RewriteRule ^(.*)\.[\d]{10}\.(js)$ $1.$2 [L]

It means that:

http://example.com/static/js/min/common.min.1234567890.js

redirected to:

http://example.com/static/js/min/common.min.js

But this will catch all .js requests from the domain, I just want to catch .js requests from / static / js / min / * .js - but this does not work:

RewriteRule ^static/js/min/(.*)\.[\d]{10}\.(js)$ $1.$2 [L]

What should be the rule?

+4
1

,

http://example.com/static/js/min/common.min.1234567890.js

http://example.com/static/js/min/common.min.js

,

.htaccess

 RewriteEngine On 

RewriteRule ^static/js/min/([^\d]*)(\d{10}).js$ static/js/min/$1js [L]

static/js/min/

RegEx, . ([^\d]*).

common.min..

$1 common.min.

, url, (\d{10}) .

1234567890.

$2 1234567890,

static/js/min/$1js

, . $1, $1, . (common.min.)

,

RewriteEngine On
RewriteRule ^static/js/min/([^\d]*)(\d{10}).js$ static/js/min/$1js [L]

enter image description here

enter image description here

+2

Source: https://habr.com/ru/post/1673076/


All Articles