Making Apache return the same page for all URLs

I am currently developing and maintaining a web application running on Apache. In this context I have sometimes needed to take the site down in order to roll out new versions of the underlying software. Instead of taking down the web server entirely and having the users get error messages from their browsers, I naturally want to present a “Down for maintenance” page.

Doing this for the root URL of the application was a simple matter of making a new configuration file, with the same ServerName parameter, in the sites-available directory. This new configuration file points at a DocumentRoot containing a single index.html containing the wanted message.

However, trouble struck when trying to access anything but the root URL. I tried redirecting all requests to the root URL with AliasMatch and RedirectMatch but kept making redirect loops. My attempts at googling for a solution kept pointing me at these two directives and mod_rewrite, from which I expected the same trouble.

After browsing the Apache documentation I stumbled upon the ErrorDocument directive, which allows specifying what should be returned in case of errors. Adding this line to my “site down” configuration made everything work:

ErrorDocument 404 /

Because the site only contains the single index.html accessing anything else will result in 404 error, which the ErrorDocument directive specifies should result in the root of the site being returned.

This is probably well known stuff for most Apache administrators, but given the trouble I had finding it, I thought it might help other newcomers to post about it.

Emacs, inserting text from the line above

Some time ago colleague using VIM showed me a nice feature in his editor. With a keystroke he could copy the character right above the cursor and move the cursor forward, thus copying the line above character by character. Not a feature one would use all the time, but nice when having to write something like this:

structWithLongName.subStruct.a = 7;
structWithLongName.subStruct.b = 9;
structWithLongName.subStruct.c = 13;

Naturally I wanted a similar feature in emacs, so I made the following:

(defun pal-get-char-above-or-below (delta)
  (save-excursion
    (let ( (orig-column (current-column)) )
      (forward-line delta)
      (forward-char orig-column)
      (if (eq orig-column (current-column))
          (buffer-substring (point) (+ 1 (point)))
        nil))))

(defun pal-insert-char-above-or-below (delta)
  (let ( (insertee (pal-get-char-above-or-below delta)) )
    (when (and insertee (not (equal insertee "\n")))
      (insert insertee))))

(defun pal-insert-char-above ()
  (interactive)
  (pal-insert-char-above-or-below -1))

(defun pal-insert-char-below ()
  (interactive)
  (pal-insert-char-above-or-below 1))

Now calling “pal-insert-char-above” will copy a character from the line above, and move the point forward. The “pal-insert-char-below” will do the same with a character from the line below.

Introduction

So – I have started a blog. I did so for a couple of reasons:

  • I have started roasting coffee myself. While experimenting with this, I have been taking notes, in order to be able to learn from my mistakes. I thought these notes might be interesting to others as well, and will place them in this blog.
  • From time to time I have wanted to write about some of the software development I am doing. A blog seems like an ideal place for stuff like this.
  • I want a place to vent frustrations about the doings of people from certain political parties.

Most of this blog will be in danish, except for this introduction and the entries about software development.