Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

1 Answer 1

up vote 5 down vote accepted

Absolutely.

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

 
discard

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.