Mobile app version of vmapp.org
Login or Join
Kristi941

: Mod-Rewrite content negotiation for mixed Accept header? I am configuring a lightweight content negotiation mechanism using Apaches's Mod-Rewrite. The configuration should deliver several different

@Kristi941

Posted in: #Apache2 #ModRewrite #SemanticWeb

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/.html [NC,R=303,L]

# serve xml on base url if requested via accept header
RewriteCond %{HTTP_ACCEPT} application/xml
RewriteRule ^resource/(.*)$ view/xml/.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/.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/.rss [NC,R=303,L]

# serve html as default response (keep at bottom)
RewriteRule ^resource/(.*)$ view/html/.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.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Kristi941

1 Comments

Sorted by latest first Latest Oldest Best

 

@Miguel251

Use the built-in content negotiation functionality with a type map. You may need to tweak your filenames / URLs or use rewrite rules after applying the type map.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme