Readers like you help support MUO. When you make a purchase using links on our site, we may earn an affiliate commission. Read More.

I want to rewrite /mini/* to /compressed/*.gz

Here's what I have so far. Not sure how to do it:

RewriteEngine on

RewriteCond %{HTTP:Accept-Encoding} gzip

RewriteCond %{REQUEST_FILENAME}.jgz -f

#

# Rewrite website.com/test/mini/* to website.com/test/compressed/*.gz

#

AddType "text/javascript" .js.jgz

AddType "text/css" .css.jgz

AddEncoding gzip .jgz

It essentially will redirect CSS and JS files to the compressed versions if GZIP compression is enabled on the clients' side.

MAKEUSEOF VIDEO OF THE DAY
SCROLL TO CONTINUE WITH CONTENT
pceasies
2010-07-23 16:49:00
I figured out the problem, it was the RewriteCond line. I have this now:# RewriteCond compressed/%{REQUEST_FILENAME}.jgz -fRewriteRule ^mini/([A-Za-z0-9-_]*..*)$ compressed/$1.jgz [NC,L]But now I don't know how to fix RewriteCond. I'd like to have it work so it checks to make sure the file exists first.
GeekLad
2010-08-05 21:47:00
I think the RewriteCond is close, but you need to change the .jgz to the orignal extension not what you're rewriting it to.
pceasies
2010-08-06 00:12:00
I want to make sure the .jgz (compressed version) exists before rewriting, otherwise it defaults to the regular.