Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If the client requests a file ending with .js from Apache, I'd like Apache to first check if there is a .js.min file of the same basename and serve it if it exists, and otherwise, serve the original .js file. Can I do that with the standard Apache mods that come with Debian?

share|improve this question
up vote 5 down vote accepted


RewriteEngine on
RewriteCond %{REQUEST_URI} \.js$
RewriteCond %{REQUEST_FILENAME}.min -f
RewriteRule (.*) $1.min [T=text/javascript]

You may want the L flag as well, if you know you don't need further rewriting.

share|improve this answer
Cool. I was thinking MultiViews would be used for something like this. BTW, I think you meant to put parens around your match, like RewriteRule (.*) $1.min. – erjiang Apr 16 '12 at 21:23
Indeed I did. Fixed. – Ignacio Vazquez-Abrams Apr 17 '12 at 2:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.