Forum Moderators: phranque

Message Too Old, No Replies

exclude folder

         

helenp

12:17 pm on Oct 17, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi, I have pregzipped files,
so I want all .css files to be served as .jgz
however I want to exclude the .css files in directory chat.

I have this but this dont work (part of htaccess file):
RewriteRule (.*)\.css$ $1\.css.jgz [L]
AddType "text/css" .css.jgz
RewriteRule ^(chat) - [L]
The first two line works perfect,
but the last line dont work.

And if possible in directory chat there is a mixed file with javascript and php, named .js.php
if possible I would like to rewrite that file to .js.php.jgz, and exclude everything else as .js, .css etc, but not important.

Thanks in advance.

lucy24

7:20 am on Oct 23, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Three extensions? Are you absolutely positive you know what you're doing?

Hm. Been around since 2003. I guess you do.

RewriteRule (.*)\.css$ $1\.css.jgz [L]

It may work, but it's inefficient. The leading (.*) means that the server captures everything in sight, and then has to backtrack until it can pick up the .css extension. And, since you're recycling the css, it can simplify to

RewriteRule ([^.]+\.css)$ $1.jgz [L]


AddType "text/css" .css.jgz

Ouch! What's a mod_mime directive doing squeezed between two mod_rewrite directives? Aren't the first two lines (using two different modules) redundant?

RewriteRule ^(chat) - [L]

The first two line works perfect,
but the last line dont work.


What is the last line intended to do? As written, it says "capture the element 'chat' if it's a top-level file or directory, don't do anything with it, and start mod_rewrite from the top". So if the Rule is intended to do nothing, I would have to say that it's working perfectly.

If you want the css-to-css.jpz stuff to happen everywhere except in the /chat/ directory, you need a preceding RewriteCond. It's too late to append an extra rule when the first one has already executed.

RewriteCond %{REQUEST_URI} !^/chat/
RewriteRule {business about css here}

g1smd

7:46 am on Oct 23, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



RewriteRule ([^.]+\.css)$ $1.jgz [L]


Unless you want your server hacked using path injection, add a slash immediately before the $1 of the target.