Forum Moderators: phranque

Message Too Old, No Replies

Apache/ModRewrite Absolute URL problem in IE6

Internet Explorer 6 SP2 doesn't like absolute URLs in CSS!

         

dan_m2k

3:12 pm on Oct 23, 2007 (gmt 0)

10+ Year Member



Hey all,

I'm slightly baffled by the the situation I'm in. I have a nice CSS layout on my page that places a background image as per:


#top-bg{
background:url(/images/top-bg.png) no-repeat 0 0;
...
}

Which works well in Firefox, IE7 etc etc... However, it *does not* work in IE6 under WinXp. When IE6 loads the page I see in the server logs that it is trying to find the background image at the wrong location relative to the document:

127.0.0.1 - - [12/Oct/2007:09:44:00 +0100] "GET /florals/images/top-bg.png HTTP/1.1" 404 342 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"

However when any other browser trys to load it, everything works fine (a 304 in this case as it's loaded from cache but still works as a 200):

127.0.0.1 - - [12/Oct/2007:09:52:51 +0100] "GET /images/top-bg.png HTTP/1.1" 304 - "http://monkey/css/all.css" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7"

I'm stumped. Either I've messed up the syntax for the absolute URL in the CSS and I'm too blind to see it or something else is going on. I suspect it may be something to do with my mod_rewrite config which (very basically) rewrites nice urls like

http://www.example.com/folder/

to a real url like
http://www.example.com/page.php?id=folder

The pertinent bits of mod_rewrite rules (thanks to some other good folks on the WW forums)


RewriteRule ^(manager/[0-9a-z._\-]*$¦editor/¦ajax/¦images/¦css/¦js/¦errors/¦go/¦include/) - [NC,L,QSA]
RewriteRule ^([0-9a-z/\-]+)/?$ /index.php?id=$1 [NC,L,QSA]

(NB, I previously posted this in the CSS forum, where nobody was able to help so I cross posted here, if I've broken any rules, please accept my apologies)

jdMorgan

9:04 pm on Oct 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Looks like an IE6 CSS bug to me (no big surprise).

The form of the background URL you're using is "server-relative" (not "absolute") and should always resolve to example.com/images/top-bg.png

Obviously, IE6 is not resolving that properly, so two solutions might be:
1) mod_rewrite to detect IE6 and strip off the errant subfolder(s).
2) Use an absolute/canonical URL, like
background:url(http://example.com/images/top-bg.png)

Jim

g1smd

10:45 pm on Oct 24, 2007 (gmt 0)

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



I have nightmares about these types of stupid bug.

dan_m2k

9:56 am on Oct 25, 2007 (gmt 0)

10+ Year Member



Oh man, I wonder how much quicker web site development would be if we didn't have IE bugs to work around!

Thanks, jdMorgan, I used your second suggestion and it's working.

Best regards
Dan