开发者

mod_rewrite preventing correct filetype icons from showing on mod_autoindex

开发者 https://www.devze.com 2023-02-09 11:09 出处:网络
I seem to have a problem which I\'ve been struggling to solve. I\'d love a bit of help here. I have a dump site where I am using mod_autoindex and FancyIndexing.

I seem to have a problem which I've been struggling to solve. I'd love a bit of help here. I have a dump site where I am using mod_autoindex and FancyIndexing.

I have my FancyIndexing icons defined in my .htaccess file. I also use mod_rewrite to pass the files through several php scripts (depending on the file extension).

Everything works great, except when a file extension is matched on a RewriteRule, Apache displays only it's default icon, and not the one specified.

All FancyIndexing resources are on the /imgindex directory, and all viewers are on the /viewers directory.

This is the relevant part of the .htaccess file (I'm currently tweaking it, so it's not optimized):

Options +Indexes
IndexOptions +XHTML +HTMLTable +FancyIndexing +FoldersFirst +SuppressHTMLPreamble +IconsAreLinks +IgnoreCase +NameWidth=*
IndexIgnore *~ imgindex viewers favicon.ico
HeaderName /imgindex/header.html
ReadmeName /imgindex/footer.html

# ------ Fancy Indexing ----------
AddIcon /imgindex/image.png .jpg .jp2 .jif .jpeg .tiff .tif .pict .pct .bmp .gif .png .psd .tga .ai .indd .fh* .fh10 .xcf .svg
AddIcon /imgindex/app.png .app
AddIcon /imgindex/movie.png .mov .mpg .mpeg .m2v .avi .divx .xvid .swf .wmv .wma .wm* .ram .rm .ogm .ogv
AddIcon /imgindex/txt开发者_开发百科.png .txt .text .log
# etc, etc.
DefaultIcon /imgindex/text.png

# ------ Rewriting --------
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^viewers/(.*)$
RewriteCond %{REQUEST_URI} !^imgindex/(.*)$
RewriteRule ^(.*).(css|cs|cpp|h|hpp|pas|xml|js|asm|inc|as|sh|bat|cmd|html)$ /viewers/view_source.php?file=$1.$2&%{QUERY_STRING} [NC,L]

RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^viewers/(.*)$
RewriteCond %{REQUEST_URI} !^imgindex/(.*)$
RewriteRule ^(.*).(jpg)$ /viewers/viewjpg.php?file=$1.$2&%{QUERY_STRING} [NC,L]

# (etc, etc.)

As I said, everything seems to work great, except for the icons. In the case above, all .css, .cs, .cpp, (etc), and all .jpg files will use the icon defined in DefaultIcon, instead of the one for its filetype (defined in AddIcon).

If I remove the RewriteRule that matches that filetype, the correct icon gets displayed.

Is this normal, expected behaviour? Any way to override it, if so?

Regards,


Ok, seems I found out why. mod_rewrite is, for some reason (a bug?) remapping all apr_read_dir() calls, which mod_autoindex uses (I ended up looking at mod_autoindex source code). Since it's considered a subrequest on the mapper module, as a workaround I just added a:

RewriteCond %{IS_SUBREQ} false

To each of the RewriteRules and it magically worked. Of course, this is just a workaround, since if you actually need a rewriterule on a subrequest, this might not work for you.

I do believe this to be a bug on mod_autoindex, since there's absolutely no reason the filename for the icon and/or description should be ANY different than the one used to actually print the output data.

There could be some obscure reasons to it though.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号