I have a use case is to host a set of files (same RDF content with different serialization formats such as RDF/XML, Turtle, and JSON-LD) in Github pages and use a w3id URL as a permanent identifier.
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.
So the idea is similar to the following.
GET http://w3id.org/foo -- redirect to --> http://foo.git.io/content.ttl
Accept: text/turtle
GET http://w3id.org/foo -- redirect to --> http://foo.git.io/content.jsonld
Accept: application/ld+json
Currently my rules look like the following.
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]
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
Accept: application/rdf+xml;q=0.9,text/turtle
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?