Forum Moderators: phranque

Message Too Old, No Replies

Conditional rewrite: rewriting when condition should be false?

         

Readie

5:29 pm on Mar 21, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have an issue on this site I'm building - for some odd reason firefox is adding an extra pixel worth of width on the main body which is screwing with the borders on either side of my title image - so I'm trying to simply create a 1px wider title image and load that if the user is using firefox.

Problem is, I got this piece of code straight from the apache website [httpd.apache.org...] - and only modified it slightly:

RewriteCond %{HTTP_USER_AGENT} ^Mozilla.*
RewriteRule ^sitemain/titl\.png$ /sitemain/title_m.png [L]
RewriteRule ^sitemain/titl\.png$ /sitemain/title.png [L]

And it's rewriting all browsers except Opera to title_m.png - which is even worse than it was before.

Just asking here if there is any better way of doing this that will actually work without negative side effects?

jdMorgan

5:53 pm on Mar 21, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The first RewriteCond will match any browser except for Opera, because all of their User-agent strings either *are* Mozilla, or start with "Mozilla/4.0 (compatible; ..."

I'd suggest that you fully-specify the Firefox/SeaMonkey/K-Meleon UA string, at least up to and including the "Gecko/" part:

RewriteCond %{HTTP_USER_AGENT} ^Mozilla/5\.0\ \(([^;]+;\ )+rv:[0-9]\.[0-9]\)\ Gecko/

- or, slightly-shorter/faster, but less restrictive:

RewriteCond %{HTTP_USER_AGENT} ^Mozilla/5\.0\ \([^)]+\)\ Gecko/


I should also add that there are many threads in our CSS forum dealing with "one-pixel-off" problems, usually related to border, padding, or inline- versus block-display differences between browser rendering engines.

Jim

Readie

6:25 pm on Mar 21, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ahh, that explains that then :)

Thank you very much again Jim, I hope I can return atleast one of these favours some day :P

I'll dig through the CSS forums when I have a bit more free time - I would prefer a CSS solution (both for my own education and because I'm not keen on relying on .htaccess for a clear layout), but it's working now, so it's fairly low priority.

Thanks again,

Mike