问题
I was wondering if someone could provide me with the typical rule, to serve the appropriate file when a resource is requested, with respect to the content type required. To be more specific here is my situation:
I have a purl URL that i redirect to an URL on my apache server. I would like to resource URL to be like a generic URL for the resource, and then serve the appropriate doc depending on the content Type: RDF, TTL, or HTML.
Hence i would like to know how to do that within the .htaccess file. Can anyone help here ?
Many thanks
回答1:
Alright, here is what i did.
I'm hosting my vocabulary on a free hosting website which allows for the manipulation of the .htacess file.
On that file i wrote some rules according to the instructions of http://www.essepuntato.it/lode, which by the way follows the instructions of http://www.w3.org/TR/swbp-vocab-pub/. I just wanted something to generate my HTML on the fly.
Here is my .htaccess file content:
# Do not remove this line, otherwise mod_rewrite rules will stop working
RewriteBase /
# Rewrite engine setup<br/>
RewriteEngine On
AddType application/rdf+xml .owl
AddType application/rdf+xml .rdf .owl
AddType text/turtle .ttl
# Rewrite rule to serve HTML content<br/>
RewriteCond %{HTTP_ACCEPT} !application/rdf\+xml.*(text/html|application/xhtml\+xml)
RewriteCond %{HTTP_ACCEPT} text/html [OR]
RewriteCond %{HTTP_ACCEPT} application/xhtml\+xml [OR]
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/.*
RewriteRule ^CommitmentOntology$ http://www.essepuntato.it/lode/http://theoceanopeninteractioninfrastructure.webege.com/CommitmentOntology [R=303,L]
# Rewrite rule to serve RDF/XML content if requested
RewriteCond %{HTTP_ACCEPT} application/rdf\+xml
RewriteRule ^CommitmentOntology$ CommitmentOntology.owl [R=303]
# Choose the default response
RewriteRule ^CommitmentOntology$ CommitmentOntology.owl [R=303]
However i have another level of indirection because i use purl address as it can be seen within the ontology (Ontology ID)
Here is the redirection on Purl:
id: /net/OceanOIS-Commitments
type: 303
seealso: http://theoceanopeninteractioninfrastructure.webege.com/CommitmentOntology
maintainers: Maatari
I don't know if it is fully right but it works. With the browser i get the HTML generated on the fly and with a proper rest client or wget i get the xml+rdf
来源:https://stackoverflow.com/questions/23497550/linked-data-rdf-content-negotiation-with-apache