<IfModule mod_rewrite.c>
# Sources:
# http://www4.wiwiss.fu-berlin.de/bizer/pub/LinkedDataTutorial/
# http://www.w3.org/TR/swbp-vocab-pub/#recipe3

# Turn off MultiViews
Options -MultiViews

# Directive to ensure *.rdf files served as appropriate content type,
# if not present in main apache config
AddType application/rdf+xml .rdf
AddType text/rdf+n3;charset=utf-8 .n3
AddType application/x-turtle .ttl
AddType application/openmath-cd+xml .ocd

# Rewrite engine setup
RewriteEngine On
RewriteBase /cd

RewriteRule index.html index.html [L]

# Rewrite rule to serve HTML content from the vocabulary URI if requested:
# * neither RDF not OpenMath CD requested
# 
# For HTML we don't do a 303 redirect.  While this is not quite compliant 
# with Linked Data best practices, the advantage is that the browser does
# not see a rewritten URL.  Then, if someone copy/pastes the URL out of 
# the browser, it remains the canonical URL, which makes more sense when
# sharing it.
RewriteCond %{HTTP_ACCEPT} !application/(rdf|openmath-cd)\+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 ^(.+)(?<!\.rdf)(?<!\.xhtml)(?<!\.ocd)$ /opt/local/activemath/www/www.openmath.org/www/$1.xhtml [L]

# Rewrite rule to serve RDF/XML content from the vocabulary URI if requested
RewriteCond %{HTTP_ACCEPT} application/rdf\+xml
RewriteRule ^(.+)(?<!\.rdf)(?<!\.xhtml)(?<!\.ocd)$ $1.rdf [R=303,L]

# Rewrite rule to serve OpenMath CD content from the vocabulary URI if requested
RewriteCond %{HTTP_ACCEPT} application/openmath-cd\+xml
RewriteRule ^(.+)(?<!\.rdf)(?<!\.xhtml)(?<!\.ocd)$ $1.ocd [R=303,L]

# Choose the default response
# ---------------------------

# Rewrite rule to serve the RDF/XML content from the vocabulary URI by default
RewriteRule ^(.+)(?<!\.rdf)(?<!\.xhtml)(?<!\.ocd)$ $1.ocd [R=303,L]

# Alternative possibilities: default to RDF/XML or to XHTML:
# Rewrite rule to serve the RDF/XML content from the vocabulary URI by default
# RewriteRule ^(.+)(?<!\.rdf)(?<!\.xhtml)(?<!\.ocd)$ $1.rdf [R=303,L]
# Rewrite rule to serve HTML content from the vocabulary URI by default
# RewriteRule ^(.+)(?<!\.rdf)(?<!\.xhtml)(?<!\.ocd)$ $1.xhtml [R=303,L]
</IfModule> 

