Advertise here: Contact FM.


htaccess and description column
July 10, 2008 3:10 PM   RSS feed for this thread Subscribe

I would like to use .htaccess to pull out a specific part of a filename and display it in the "Description" column of a file directory on an apache web server.

All files in this directory are formatted like this:

aaaaaaaa-bbbb-c~c-d~d.ext

There is always a hypen between each block, and blocks "a" and "b" are always the same length. "c" and "d" are variable lengths, symbolized by the ~, but they always consist of alphanumeric characters.

Ideally, I'd like for the "c" block to be pulled out and displayed in the "description" column when users browse this directory. Also OK would be to display both "c" and "d" in the description, but just "c" would be perfect.

My poor regex-fu combined with my lack of comprehensive understanding of htaccess goodness is keeping me from doing this successfully, assuming it can be done at all.
posted by maxwelton to computers & internet (1 comment total)
First, expectations check: The description in a mod_autoindex, FancyIndexing directory can't be automatically generated from the filename, as far as I know. It has to be explicitly specified per-file in .htaccess. So you'd have to generate the .htaccess from the directory contents, and then regenerate it whenever files appear, disappear, or change.

That said, this should do that, run in the directory in question:
#!/bin/sh
for filename in *
do
echo AddDescription \"$(echo $filename | cut -d- -f3)\" $filename
done > .htaccess

(Please don't kill my formatting, preview...)

Note that that overwrites your .htaccess. If you have anything in it already, you'll need to concatenate the static parts with the output of that script. (If you don't know how, let me know.)

Also note that there's no regular expressions there! You have a perfectly good field delimiter, so you can use "cut" to just take the third field.
posted by mendel at 5:54 PM on July 10


« Older Can this possibly be Xanax wit...   |   Help us entertain a bunch of t... Newer »

You are not logged in, either login or create an account to post comments



Related Questions
Just like the neighbor's cat in your kids' sandbox... June 22, 2008
Holy Grail of web-based file management? June 11, 2008
How do I delete a stubborn mpeg file? March 27, 2007
Should we use save our Illustrator files as .ai,... March 20, 2007
On WinXP, every minute, I get a new file in my... January 4, 2005