W3C home > Mailing lists > Public > public-swbp-wg@w3.org > November 2005

[VM] http examples, low-level alternative/hack

From: Benjamin Nowack <bnowack@appmosphere.com>
Date: Tue, 22 Nov 2005 17:27:23 +0200
To: SWBPD WG <public-swbp-wg@w3.org>
Message-ID: <PM-EH.20051122172723.890.1.1D@>


the "apache cookbook"[1] idea is great. I'm not sure if the 
following is helpful or out of scope, there are probably better
ways to make apache return resource descriptions, but there may
be situations where someone would like to publish an RDF 
vocabulary but doesn't have access to apache's rewrite or 
multiviews switches. However, custom 404s via .htaccess files 
seem to be enabled by almost every provider of hosted webspace.
So, a simple
ErrorDocument 404 /catch_404.php
line in a .htaccess file can be used to easily lift the request
processing to scripting languages like php, perl, or python. A 
sample (PHP) script file that supports basic slash-ont serving 
could contain

/* requested URI, e.g. /ns/example/classA */

/* detect ontology and term by looking for "ns" prefix */
if(preg_match("/\/ns\/([^\/]+)[\/]?(.*)/", $ru, $matches)){

  /* check rdf accept headers */
  if(strpos($_SERVER["HTTP_ACCEPT"], "application/rdf+xml")!==false){
    if($term_name && file_exists($term_path)){
      header("HTTP/1.0 200 OK");
      header("Content-Type: application/rdf+xml");
      $fp=fopen($term_path, "r");
    elseif(!$term_name && file_exists($ont_path)){
      header("HTTP/1.0 200 OK");
      header("Content-Type: application/rdf+xml");
      $fp=fopen($ont_path, "r");
  /* try html */
      header("HTTP/1.0 200 OK");
      header("Content-Type: text/html");
      $fp=fopen($html_path, "r");
  /* serve result */
    header("HTTP/1.0 404 Not Found");


(I didn't test the code above, it may contain errors. The
basic idea works, though. 303s can be implemented in a 
similar way)

This mechanism can also be useful when Rewrite *is* available,
RewriteEngine on
RewriteRule \/ns\/ /catch_ont.php
enables a catch_ont script which is not limited to apache's 
options but can for example access a database or scan the local
file system. Different ontology versions can be served based on
parameters, without having to hard-code the pointers in the 
.htaccess files etc.

As I said, the 404 thing is a bit hacky, but it may be a useful
work-around for TAG-friendly vocabulary publishing on cheap, 
hosted web servers. (Although it seems that many hosters are
enabling the rewrite module these days. Not sure about the
multiviews toggle...)



[1] http://www.w3.org/2001/sw/BestPractices/VM/http-examples/2005-11-18/

Benjamin Nowack

Kruppstr. 100
45145 Essen, Germany
Received on Tuesday, 22 November 2005 16:28:10 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:09:45 UTC