Redirect via HTACCESS only files

Hi

I’ve got a website ( [URL]http://unina.stidue.net[/URL] ) managed by a simply directory listing by apache “fancyed” with header, footer and css.
I want that ALL and ONLY files (not dirs) must be served by PHP script who can do a CAPTCHA test before stream the file.
I think I can acheive this using a rule in my .htaccess file that makes these transformations:

[CODE]
http://unina.stidue.net/ -> http://unina.stidue.net/ (No changes)

http://www.unina.stidue.net/folder1/ -> http://www.unina.stidue.net/folder1/ (No changes)

http://unina.stidue.net/fold1/fold2/ -> http://unina.stidue.net/fold1/fold2/ (No changes)

http://unina.stidue.net/folder1/file1.ext -> http://unina.stidue.net/include/fmanager.php?file=/folder1/file1.ext

http://www.unina.stidue.net/fold1/fold2/file2.ess -> http://www.unina.stidue.net/include/fmanager.php?file=/fold1/fold2/file2.ess
[/CODE]

For now, my htaccess is like:

[CODE]
RewriteEngine On

Options Indexes FollowSymLinks
IndexOptions Charset=UTF-8
IndexOptions +FancyIndexing
IndexOptions +VersionSort
IndexOptions +HTMLTable
IndexOptions +FoldersFirst
IndexOptions +IconsAreLinks
IndexOptions +IgnoreCase
IndexOptions +SuppressDescription
IndexOptions +SuppressHTMLPreamble
IndexOptions +XHTML
IndexOptions +IconWidth=16
IndexOptions +IconHeight=16
IndexOptions +NameWidth=55
IndexOrderDefault Ascending Name
HeaderName /include/header.html
ReadmeName /include/footer.html

IndexIgnore /include
IndexIgnore /.htaccess
IndexIgnore /COPYING
IndexIgnore /README.md
IndexIgnore /vhost.conf
IndexIgnore /favicon.gif
IndexIgnore /favicon.ico
IndexIgnore /img
IndexIgnore /contribuisci
IndexIgnore /google898fc143c2921769.html
IndexIgnore /robots.txt
IndexIgnore /sitemap.xml
IndexIgnore /sitemap.xsl
IndexIgnore /y_key_70f072abda42ab66.html
IndexIgnore /e72
IndexIgnore /c7
IndexIgnore /wf
IndexIgnore SSS

AddIcon /include/icons2/type_application.png .exe .app .EXE .APP
AddIcon /include/icons2/type_binary.png .bin .hqx .uu .BIN .HQX .UU
AddIcon /include/icons2/type_box.png .tar .tgz .tbz .tbz2 bundle .rar .TAR .TGZ .TBZ .TBZ2
AddIcon /include/icons2/type_rar.png .rar .RAR
AddIcon /include/icons2/type_html.png .htm .html .HTM .HTML
AddIcon /include/icons2/type_code.png .htx .htmls .dhtml .phtml .shtml .inc .ssi .c .cc .css .h .rb .js .rb .pl .py .sh .shar .csh .ksh .tcl .as
AddIcon /include/icons2/type_database.png .db .sqlite
AddIcon /include/icons2/type_disc.png .iso .image
AddIcon /include/icons2/type_document.png .ttf
AddIcon /include/icons2/type_excel.png .xlsx .xls .xlm .xlt .xla .xlb .xld .xlk .xll .xlv .xlw
AddIcon /include/icons2/type_flash.png .flv
AddIcon /include/icons2/type_illustrator.png .ai .eps .epsf .epsi
AddIcon /include/icons2/type_pdf.png .pdf .PDF
AddIcon /include/icons2/type_php.png .php .phps .php5 .php3 .php4 .phtm
AddIcon /include/icons2/type_photoshop.png .psd
AddIcon /include/icons2/type_monitor.png .ps
AddIcon /include/icons2/type_powerpoint.png .ppt .pptx .ppz .pot .pwz .ppa .pps .pow
AddIcon /include/icons2/type_swf.png .swf
AddIcon /include/icons2/type_text.png .tex .dvi
AddIcon /include/icons2/type_vcf.png .vcf .vcard
AddIcon /include/icons2/type_word.png .doc .docx
AddIcon /include/icons2/type_zip.png .Z .z .tgz .gz .zip
AddIcon /include/icons2/type_globe.png .wrl .wrl.gz .vrm .vrml .iv
AddIcon /include/icons2/type_android.gif .apk .APK

AddIconByType (TXT,/include/icons2/type_text.png) text/*
AddIconByType (IMG,/include/icons2/type_image.png) image/*
AddIconByType (SND,/include/icons2/type_audio.png) audio/*
AddIconByType (VID,/include/icons2/type_video.png) video/*
AddIconByEncoding (CMP,/include/icons2/type_box.png) x-compress x-gzip

AddIcon /include/icons2/back.png …
AddIcon /include/icons2/information.png README INSTALL
AddIcon /include/icons2/type_folder.png ^^DIRECTORY^^
AddIcon /include/icons2/blank.png ^^BLANKICON^^

DefaultIcon /include/icons2/type_document.png

order allow,deny
allow from all

ErrorDocument 400 /include/400.html
ErrorDocument 401 /include/400.html
ErrorDocument 403 /include/403.html
ErrorDocument 404 /include/400.html

RewriteRule ^(.+)/(.+).(.+)$ include/fmanager.php [L]
[/CODE]

But doesen’t work (I can’t manage only files and I’m not able to set /include/ and utility files (i.e. files in root, hidden via indexIgnore) “transparent” to this htaccess.
Can you help me?
Thank you so much.

These two lines only related to each other, probably should keep them together:

RewriteEngine On RewriteRule ^(.+)/(.+).(.+)$ include/fmanager.php [L]

Having said that, you don’t have the logic in this section to do what you want. You will need to exclude /includes and any other subdirectories that could match the first group, and “unaccessible” files and directories that match all three. See the reference documentation.

I admit I didn’t look very carefully at the whole htaccess file, but I’m pretty sure you’ll need the QSA flag:

RewriteRule ^(.+)/(.+).(.+)$ include/fmanager.php [L,QSA]