I am configuring a lightweight content negotiation mechanism using Apaches's Mod-Rewrite. The configuration should deliver several different data representations (for instance, HTML, XML, RDF/XML, and RSS, although I actually have to consider a few more in my application) on a base resource URL depending on the Accept header of the request:
# serve html on base url if requested via accept header
RewriteCond %{HTTP_ACCEPT} text/html [OR]
RewriteCond %{HTTP_ACCEPT} application/xhtml\+xml
RewriteRule ^resource/(.*)$ view/html/$1.html [NC,R=303,L]
# serve xml on base url if requested via accept header
RewriteCond %{HTTP_ACCEPT} application/xml
RewriteRule ^resource/(.*)$ view/xml/$1.xml [NC,R=303,L]
# serve rdf on base url if requested via accept header
RewriteCond %{HTTP_ACCEPT} application/rdf\+xml
RewriteRule ^resource/(.*)$ view/rdf/$1.rdf [NC,R=303,L]
# serve rss on base url if requested via accept header
RewriteCond %{HTTP_ACCEPT} application/rss\+xml
RewriteRule ^resource/(.*)$ view/rss/$1.rss [NC,R=303,L]
# serve html as default response (keep at bottom)
RewriteRule ^resource/(.*)$ view/html/$1.html [NC,R=303,L]
This works pretty fine if the request is sending pure Accept headers, but I run into some trouble when mixed Accept headers are sent. In that case, my configuration does not respect any given q-value in the header, and I end up serving the first matching content type according to the (arbitrary) ordering of my RewriteRules. E.g., I incorrectly serve text/html for the following request:
Accept: application/rdf+xml;q=0.5,text/html;q=.3
Is there any way how I can make my configuration take the q-values of the Accept header into account? Any help is appreciated.