htaccess and description column
July 10, 2008 3:10 PM   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 answer 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/shfor filename in *do     echo AddDescription \"$(echo $filename | cut -d- -f3)\" $filenamedone  > .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, 2008


« Older Is it Xanax or is it stress?   |   What to do with four teenage girls? Newer »
This thread is closed to new comments.