Reputation: 291
I've been trying this for the last 2h.
how can I use mod rewrite to do this:
/assets/app.min.4364736473.js -> /assets/app.min.js
/assets/app.min.4364736473.css -> /assets/app.min.css
Upvotes: 2
Views: 1227
Reputation:
Not that there's anything wrong with nikoshr's answer, but perhaps this is more versatile, working anywhere in the site that the format is used, since it's not likely to be used for any usual extension. In case it is, it checks that the file with the number doesn't exist before executing. The .min
is optional, it works with or without it:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)\.\d+(\.(?:js|css))$ $1$2
Finally, not using the [L]
flag since other rules might need to be applied on the rewritten URL and no need to stop that happening.
It will only work properly in a .htaccess
or <Directory>
context. Otherwise (in a root config or <VirtualHost>
context) it will need modifying for the file test to work or existing files won't be noticed and it will execute anyway.
Upvotes: 5
Reputation: 33344
It could be
RewriteEngine on
RewriteRule /assets/app\.min\.\d+\.js$ /assets/app.min.js [L]
RewriteRule /assets/app\.min\.\d+\.css$ /assets/app.min.css [L]
Upvotes: 2