Problems with .htaccess and AFP over Netatalk

After yesterdays triumph of establishing contact with my virtual server over AFP, using Netatalk, I was perplexed today to find that my .htaccess files weren’t having any effect. Listing the files on the shared volume on my Mac seemed to show that they were there:

~$ ls -Al /Volumes/Home Directory/www/sites/jackspeak/site/
total 736
-rwxr-xr-x   1 simon  simon    401  6 Apr 18:08 .htaccess
drwxr-xr-x@ 10 simon  simon    296  5 Apr 11:30 .svn
-rwxr-xr-x@  1 simon  simon   2941  5 Apr 11:30 500.html

But running the same command on the Linux virtual server showed very different results:

~$ ls -Al /www/sites/jackspeak/site/
total 736
-rwxr-xr-x   1 simon  simon    401  6 Apr 18:08 :2ehtaccess
drwxr-xr-x@ 10 simon  simon    296  5 Apr 11:30 :2esvn
-rwxr-xr-x@  1 simon  simon   2941  5 Apr 11:30 500.html

Apache wasn’t seeing any .htaccess files because there wasn’t any there… something had translated the “.” into “:2e”. What was this strange set of characters “:2e” which was screwing with my files?

To quote the Netatalk manual:

With OS X Apple introduced the AFP3 protocol. One of the most important changes was that AFP3 uses unicode names encoded as UTF-8 decomposed. Previous AFP/OS versions used codepages, like MacRoman, MacCentralEurope, etc.

afpd needs a way to preserve extended macintosh characters, or characters illegal in unix filenames, when saving files on a unix filesystem. Earlier versions used the the so called CAP encoding. An extended character (>0x7F) would be converted to a :xx sequence, e.g. the Apple Logo (MacRoman: 0XF0) was saved as :f0. Some special characters will be converted as to :xx notation as well. ‘/‘ will be encoded to :2f, if -usedots is not specified, a leading dot ‘.’ will be encoded as :2e.

The solution is to configure any shares which requires dot files not to use the hex translation. Luckily this is fairly easy and below is an extract from my Netatalk AppleVolumes.default, in Debian this file can be found at /etc/netatalk/AppleVolumes.default:

/www/sites/             "Sites on $h" options:usedots
/www/logs/              "Site Logs on $h"

For the first shared volume, which is also used by Apache, I don’t want the hex translation for dot files (my precious .htaccess files!), whereas for the log files directories I’m not worried about that. (BTW, the $h is replaced by the hostname, so “Sites on $h” becomes “Sites on vmachine1” for a machine called “vmachine1”.)

See also my post on Specifying the Finder Icon with Avahi, to ensure your machines show up as pretty as you want in the Shared area of Finder.

4 thoughts on “Problems with .htaccess and AFP over Netatalk”

Leave a Reply

Your email address will not be published. Required fields are marked *