Nan*_*ana 5 apache mod-rewrite content-negotiation github-pages linked-data
我有一个用例是在 Github 页面中托管一组文件(具有不同序列化格式的相同 RDF 内容,例如 RDF/XML、Turtle 和 JSON-LD),并使用w3id URL作为永久标识符。
此外,我想在该永久 URL 上进行内容协商。如果我将文件托管在 Apache 服务器中,这将是微不足道的,但不幸的是 Github 页面不支持内容协商。所以我想看看我可以在多大程度上使用 URL 重写规则来做到这一点。
所以这个想法类似于以下内容。
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
Run Code Online (Sandbox Code Playgroud)
目前我的规则如下所示。
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]
Run Code Online (Sandbox Code Playgroud)
尽管这适用于大多数情况,但在某些极端情况下会中断。例如,如果有一个像下面这样的接受头
Accept: application/rdf+xml;q=0.9,text/turtle
Run Code Online (Sandbox Code Playgroud)
这将返回 application/rdf+xml (因为第一个规则匹配),尽管根据内容协商它应该返回乌龟。有谁知道改进规则来处理这种极端情况的方法?
| 归档时间: |
|
| 查看次数: |
785 次 |
| 最近记录: |