Can you help me with URL rewrite directories?

pceasies July 23, 2010
Pinterest Stumbleupon Whatsapp

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.

  1. pceasies
    July 23, 2010 at 4:49 pm

    I figured out the problem, it was the RewriteCond line. I have this now:

    # RewriteCond compressed/%{REQUEST_FILENAME}.jgz -f
    RewriteRule ^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
      August 5, 2010 at 9:47 pm

      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
        August 6, 2010 at 12:12 am

        I want to make sure the .jgz (compressed version) exists before rewriting, otherwise it defaults to the regular.