I think I have this site working with Internet Explorer

08/15/2008 16:38:08

Getting a real website to work with Internet Explorer, without resorting to endless tricks and workarounds is a real pain in the ass. Someone needs to just delete all the source code for that program so that we can just move one…

However, that seems unlikely to happen any time soon, unfortunately.

Specifically, I was having trouble meeting the following criteria:

  • page content is written in valid XHTML 1.1 plus MathML 2.0
  • content-type needs to be application/xhtml+xml for Firefox and other real browsers
  • content-type needs to be text/html for IE

Because I want MathML to work on my site (more as a matter of pride than for any real purpose), I have to serve the content as application/xhtml+xml. With this content type, a real browser (e.g. Firefox) knows what to expect and handles it appropriately. This allows the display of mathematical formulas, such as:

<< x_(1,2) = (-b+-sqrt(b2–4ac))/(2a) [quadratic equation solution]>>

However, as soon as I enabled the proper serving of XHTML 1.1, it effectively turned off access to my site from Internet Explorer. Instead of accessing a page, the user was offered the chance to download the page as an unusable file. Therefore, IE needs the content served as text/html.

I could have two versions of the content, one ending in .html and one in .xhtml so that different browsers are served the appropriate version, but that would be a pain to keep up with. So this “solution” was not acceptable to me.

I think, finally, that today I have solved this problem.

After much digging on the internet, I finally found a solution that I was able to implement on my site via .htaccess.

  1. I had already set the default data type:

    DefaultType application/xhtml+xml
    
  2. Then I had to change the content-type to text/html for requests from IE:

    # Make Internet Explorer Happy
    
    # If getting homepage
    RewriteCond %{HTTP_USER_AGENT} .*MSIE.*
    RewriteCond %{REQUEST_URI} ^/?\(
    RewriteRule ^\)  index.html [T=text/html]
    
    # If asking for a directory, serve back the index (it has no extension here)
    RewriteCond %{HTTP_USER_AGENT} .*MSIE.*
    RewriteCond %{REQUEST_URI} ..*\/\(
    RewriteRule (.*)/\)  $1/index [T=text/html]
    
    # Otherwise, try to just send the file as html
    RewriteCond %{HTTP_USER_AGENT} .*MSIE.*
    RewriteRule .* - [T=text/html]
    

I have multiple steps in order to match certain request. Step 1 matches the home page, which is stored in /index.html. Step 2 matches directories, which store their main page in the directory in a file named index with no extension. Step 3 matches everything else (which might cause problems with images and other files down the road, but I’ll deal with that later….)

This seems to work so far - I still have access to MathML from Firefox, and I seem to be able to access the site from IE on Windows. But it’s still a crock to have to do this.

(Of course, getting the layout and other features right is another story. But for now, I’ll settle for seeing that the site exists!)

Similar Pages