views:

569

answers:

2

I just found out that by converting PNG32 to PNG8 via Photoshop will fix the PNG transparency bug in IE<=6.

So I had this thought that instead of serving PNG32 to all browser, why not serve PNG8 if the client is using IE<=6.

I'm not really an expert when it comes to htaccess/httpd directives so I'm here for help.

The title is the psuedocode itself.

A: 

Put this in your .htaccess

RewriteEngine on
RewriteRule ^/(.*)\.png$ /$18.png [L,QSA]

Should work.

okoman
This doesn't check for browser version IE<=6, does it?
schnaader
I understand that that directive forwards some.png to some8.png, but does it handle IE browser detection too. Oh, I also forgot the check if the file exists too.
ken
It does not check for IE<=6, nor does it check whether the file exists.
cjm
Use cjm's .htaccess. He read the question more carefully I guess... Sorry
okoman
+7  A: 

I haven't actually tried this, but I think it should work:

RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/4.0\ \(compatible;\ MSIE\ [1-6]\.
RewriteCond %{REQUEST_FILENAME} ^(.+)(\.png)$
RewriteCond %18%2 -f
RewriteRule ^(.+)\.png$ $18.png [L,QSA]

The first line turns mod_rewrite on (and can be omitted if you've already done that). The second does the IE <= 6 filter. The third is mainly to split the filename for the fourth line, which checks to see if <filename>8.png exists. The fifth line actually does the redirect.

cjm
i'll give feedback as soon as i run this delicious script
ken
unfortunately, it failed to work. Tested it using IE6
ken
In what way did it fail? Try using only the HTTP_USER_AGENT condition, or only the REQUEST_FILENAME conditions, to see which one is wrong.
cjm
I've added backslashes before the spaces in the IE regex; see if that works better.
cjm
yey, It actually works! I kept on clearing IE's cache but only a browser restart will do the trick.
ken