5

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?

Nandana
  • 1,240
  • 8
  • 17
  • Similar questions: [Mod-Rewrite content negotiation for mixed Accept header?](http://webmasters.stackexchange.com/q/76884/17633) (on [webmasters.se]) and [Redirect depending on preferred language (Accept-Language) with .htaccess](http://serverfault.com/q/655834/131794) (on [sf]). – unor Feb 27 '15 at 17:39
  • Thanks for the pointers @unor !! Apparently there is no solution for this, isn't it? – Nandana Feb 27 '15 at 21:26
  • I didn’t find one, but I still hope it’s possible *somehow* (without server-side scripting). – unor Feb 28 '15 at 01:00

1 Answers1

0

I think you would have to make 0-byte dummies of the actual files, e.g. foo.ttl, foo.jsonld etc and make sure their types are declared with AddType, then the regular content negotiation can work for http://example.com/foo.

But instead of serving the 0-byte files, have RewriteRule foo.ttl etc for each file so that they are redirected out to the 'real' location. Quite verbose, yes, but should then work correctly even for complex Accept headers with q= and multiple types.