Forum Moderators: phranque

Message Too Old, No Replies

Trouble with!-d

mod_rewrite and directory indexes

         

davistv

7:06 pm on Mar 2, 2006 (gmt 0)

10+ Year Member



I've been playing with these rules for most of the day, but I can't seem to get the right syntax on this... Here are my rules right now:

RewriteEngine on
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^/content\.jsp\?sectionId=11$ [my.com...] [L,R]
RewriteCond "%{REQUEST_FILENAME}"!awstatsicons
RewriteCond "%{REQUEST_FILENAME}"!j_security_check
RewriteCond "%{DOCUMENT_ROOT}%{REQUEST_FILENAME}"!-f
RewriteCond "%{DOCUMENT_ROOT}%{REQUEST_FILENAME}"!-d
RewriteRule ^(.*)$ /friendly.php?s=$1 [L,PT]

The problem happens when someone goes to http://my.com/dir or http://my.com/dir/. There's an index.html in some directories, but when a form is included with an iframe tag whose src attribute points to the directory and not the file directly, the last rule gets applied instead of just serving the directory index.

How can I adjust these rules so that directory indexes get served whenever they exist? It could be an index.html, default.htm, index.php, etc.

TIA!
Troy

[edited by: jdMorgan at 6:25 pm (utc) on Mar. 3, 2006]
[edit reason] De-linked. Obscured URLs [/edit]

extras

5:59 pm on Mar 3, 2006 (gmt 0)

10+ Year Member



As far as I know, REQUEST_FILENAME already contains DOCUMENT_ROOT.

So, these should be changed:
RewriteCond "%{DOCUMENT_ROOT}%{REQUEST_FILENAME}"!-f
RewriteCond "%{DOCUMENT_ROOT}%{REQUEST_FILENAME}"!-d

like this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

Or like this:
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d

(I don't think you really need double quotes.)

jdMorgan

6:27 pm on Mar 3, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This rule is broken as well:

RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^/content\.jsp\?sectionId=11$ https://my.com/content.jsp?sectionId=11 [L,R]

Should be:

RewriteCond %{SERVER_PORT} ^80$
RewriteCond %{QUERY_STRING} ^sectionId=11$
RewriteRule ^/content\.jsp\$ https://my.com/content.jsp [L,R]

Jim