Tweaking Rublog

It’s taken a little fiddling, but I have tweaked Rublog to do the basics for me in running this blog.

The main things I was looking for in blogging software were:

  • Local editing and uploading of entries as files (to allow me to version control all entries locally before upload)
  • WYSIWYG editing of html files

Links with SCM or version control tools seem very limited with most tools which I find very surprising. I don’t want all my content just sitting on someone else’s server with all the attendant backup problems. Also, I don’t fancy a database for blog entries as they are very difficult to version control.

I did wonder if I could tweak Rublog to generate static HTML which I could then upload, but realised that things like the calendar worked against that. I also found an ISP (beyondperception.net) who has Ruby installed and who has allowed me lots of freedom in installing other packages and configuring things.

It would be nice to have a commenting capability in Rublog, and who knows, I may get around to a simple form of that.

I was testing with Apache on Windows and then uploading to a Unix server. As a result, I wanted to create a directory structure which allowed easy copying of files around. I also discovered my ISP had only barebones Ruby installed with no libraries, so I had to install those appropriately. Adding to $LOAD_PATH and using relative pathnames for my data files fixed that.

One extra change was to add a function to read the mtime (mod time) of the blog entries from an RCS keyword ($Date: 2004/04/09 $) which is in HTML commend header. This is auto updated by my version control software (Perforce) when I submit the file, rather than when it might get copied up to the server which could be sometime later.

Mod_rewrite fun

My installation was made a little more interesting by the fact that I needed to use Apache mod_rewrite on the domain name for this blog (pointing it at a sub-directory of the main site), and I wanted to have nice clean browser URLs. Thus URLs of the form http://mainhost.com/subsite/blog/index.cgi should be converted to http://subhost.com/blog, and such changes should also be reflected in the URLs used within Rublog (e.g. for links and print styles etc).

PragDave kindly pointed out that he achieved the clean URL effect using a single ScriptAlias in his Apache configuration with no changes to Rublog. Unfortunately this wouldn’t work for me since I use shared hosting and only have .htaccess files to use to configure this sort of thing (in which ScriptAlias is not allowed). Thus I got to mess a little with mod_rewrite, and I also needed to change the Rublog code a little to make URL creation happen in a single place and tweak that function (instead of just reading ENV['SCRIPT_NAME']).

What I ended up with in my .htaccess seems pretty simple (just took some trial and error and local testing so that I could get at the mod_rewrite log to see why things weren’t working along the way):

# Redirect the robertcowham.com to sub-directory and blog references to appropriate .cgi
RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST}  robertcowham.com$
RewriteRule ^blog/$       /robertcowham/blog/index.cgi  [L]

RewriteCond %{HTTP_HOST}  robertcowham.com$
RewriteRule ^blog(.*)     /robertcowham/blog/index.cgi$1  [L]

# Anything not already caught by the above rules will be caught by this next one.
RewriteCond %{HTTP_HOST} robertcowham.com$
RewriteRule ^(.*)        /robertcowham/$1

With a single .htaccess in the robertcowham subdirectory which turned “RewriteEngine off”.

http://www.robertcowham.com/blog/wp-content/plugins/sociofluid/images/digg_48.png http://www.robertcowham.com/blog/wp-content/plugins/sociofluid/images/reddit_48.png http://www.robertcowham.com/blog/wp-content/plugins/sociofluid/images/stumbleupon_48.png http://www.robertcowham.com/blog/wp-content/plugins/sociofluid/images/technorati_48.png
blog comments powered by Disqus