title: Content negotiation using mod_rewrite / RewriteCond rules
body: <p>I have a use case is to host <a href="https://github.com/nandana/nandana.github.io/tree/master/foaf" rel="nofollow">a set of files</a> (same RDF content with different serialization formats such as RDF/XML, Turtle, and JSON-LD) in Github pages and use <a href="https://w3id.org/" rel="nofollow">a w3id URL</a> as a permanent identifier. </p>
  
  <p>Further, I want to have content negotiation on that permanent URL. This would be trivial if I hosted my files in an Apache server but unfortunately Github pages don't support content negotiation. So I am trying to see to which extent I can do that with URL rewriting rules. </p>
  
  <p>So the idea is similar to the following. </p>
  
  <pre><code>GET http://w3id.org/foo  -- redirect to --&gt; http://foo.git.io/content.ttl
  Accept: text/turtle
  
  GET http://w3id.org/foo  -- redirect to --&gt; http://foo.git.io/content.jsonld
  Accept: application/ld+json
  </code></pre>
  
  <p>Currently my rules look like the following.</p>
  
  <pre><code>Options +FollowSymLinks
  RewriteEngine on
  RewriteCond %{HTTP_ACCEPT} ^.*application/rdf\+xml.* 
  RewriteRule ^foaf$ http://nandana.github.io/foaf/card.rdf [R=303,L]
  RewriteCond %{HTTP_ACCEPT} ^.*text/turtle.* 
  RewriteRule ^foaf$ http://nandana.github.io/foaf/card.ttl [R=303,L]
  RewriteCond %{HTTP_ACCEPT} ^.*application/ld\+json.* 
  RewriteRule ^foaf$ http://nandana.github.io/foaf/card.jsonld [R=303,L]
  RewriteRule ^foaf$ http://nandana.github.io/foaf/card.html [R=303,L]
  </code></pre>
  
  <p>Though this works for majority of the cases, it would break for some corner cases. For example, if there is an accept header like the following </p>
  
  <pre><code>Accept: application/rdf+xml;q=0.9,text/turtle
  </code></pre>
  
  <p>This will return application/rdf+xml (because the first rule matches) though according to the content negotiation it should return turtle. Does anyone know a way to improve the rules to handle this corner case?</p>