2

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

1
  • Perhaps you could choose an answer to accept? It would be good to mark the question completed. Thanks. Commented Feb 16, 2017 at 5:07

2 Answers 2

5

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I try to stick to the simplest rules that can do the job but yours can be useful
Awesome ! Works perfect.
2

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]

2 Comments

ty..nope can't get it to work. I had something similar to begin with RewriteRule /assets/app\.min\.\d+\.(js|css)$ $1.$3 [L]
got it :) there was uppercase letter i in the name so \d+ wasn't working...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.