You are here

Keeping documents accessible

Submitted by cafuego on 20 May, 2007 - 13:39

As we were going through our web server logs this morning, looking for 404 - page not found errors, it turns out quite a few people have linked to documents in the /osia and /osv directories on our old website.

OpenOffice.org Impress icon These directories don't live in the same location on our new website. To keep things tidy we moved them into a directory called /files. So when we switched over, all those links were broken. Of course we can copy the documents back to where they were, but there is something to be said for keeping the web site tidy.

Luckily, apache has a module called mod_rewrite, which allows the web master to use regular expression matching on any web request and modify the request as they see fit.

With a few simple lines in the web server config file or a .htaccess file, legacy documents can remain accessible to all, whilst keeping your web tree clean. 

  RewriteCond %{REQUEST_URI} ^/osia/
  RewriteRule ^(.*)$ /files/$1 [L,R=301]

The first rule here is a conditional rule. Processing will continue only if a requested url starts with "/osia/". If this is the case, the second rule will essentially prepend the string "/files" to the request, thus for instance turning /osia/ODF.odp into /files/osia/ODF.odp. As a courtesy, it even sends a 301 - resource has moved permanently header to the browser, so bookmarks can be automatically updated.