Re: please add Accept header to http request containing application/xhtml+xml

Actually, just for the record, when a client does not send an Accept
header at all, it has the same meaning as "Accept: */*".

Furthermore, if a resource is coded for application/xhtml+xml, is
should be sent as such when the Accept header is empty.

Although far the full content negotiation specification, here is the
Apache rule I use when I cannot use a proper content negotiation with
a type-map (.var):

<IfModule mod_rewrite.c>
	RewriteEngine On
	RewriteCond %{HTTP_ACCEPT} ^$ [OR]
	RewriteCond %{HTTP_ACCEPT}
\bapplication/xhtml\+xml\b(?!(?>[^,]*?\bq=)0(?:\.0{1,3})?(?:\Z|[\s,;]))
[NC]
	RewriteRule \.html$ - [type=application/xhtml+xml;charset=UTF-8]
</IfModule>

- It will serve application/xhtml+xml when the Accept header is empty
(compatible with the current version of the W3C Validator, no
warning).

- When there is an Accept header, it will only serve
application/xhtml+xml when "application/xhtml+xml" is listed and with
a "q" higher than 0 (compatible with Internet Explorer, and of course
Opera, Firefox, Safari, etc., but not fully correct as it does not
check other q-values).


A little remark: when you use this rule in combination with a content
negotiation using a type-map (.var) for e.g. language negotiation, you
should add text/html AND application/xhtml+xml  in the .var file for
it to work as expected:

URI: index.fr.html
Content-language: fr
Content-type: text/html;qs=0.5

URI: index.fr.html
Content-language: fr
Content-type: application/xhtml+xml

URI: index.en.html
Content-language: en
Content-type: text/html;qs=0.5

URI: index.en.html
Content-language: en
Content-type: application/xhtml+xml

URI: index.en.html
Content-type: text/html;qs=0.5

URI: index.en.html
Content-type: application/xhtml+xml


You can test it live on http://alexandre.alapetite.net/

Cordially,
Alexandre Alapetite
http://alexandre.alapetite.net/cv/

Received on Monday, 21 April 2008 08:58:31 UTC