View Single Post

  #1 (permalink)  
Old 12-05-2006
Christoph Burschka
 
Posts: n/a
Default xhtml, htaccess and accept-headers

(This is barely related to PHP, but from experience it seems that most
PHP developers dabble in .htaccess and HTTP at some point.)

I recently noticed that even though my pages are all written conforming
to xhtml standards, they were parsed as html because the server sent a
text/html content type.

So I renamed all the files to .xml files, so the server would send them
with an application/xml header. It worked like a charm - Firefox's page
info now showed that the page was considered as a "real" xml file.

It was wonderful until I tried to visit the page with lynx (text-only
browser). It seems that older browsers are incapable of supporting xhtml
- which in this case is annoying, because lynx would be able to parse
the pages just fine. It is just getting stumped by the server's
"application/xml" header.

There's a silver lining. lynx and Firefox are both well-behaved browsers
and send proper Accept headers - Firefox's preference is "text/xml,
application/xml, application/xhtml+xml, text/html [...]", while lynx
wants "text/html [...]".

---

Now all I need is a way to determine the preferred content type and then
send the appropriate headers.

I know this could be done in PHP, but just for performance reasons I
wanted to know if there's a way to do it from inside .htaccess - these
pages are simple, static files and to launch the PHP parser just for
content negotiation seems a bit overboard.

Any ideas?

--
CB
Reply With Quote