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.
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.
This thread is closed to new comments.
That said, this should do that, run in the directory in question: (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