mod_autoindex does not respect mod_rewrite rules
I have a directory structure similar to:
public_html/
example.com/
index.php
subdir/
file.jpg
I'm using shared hosting, so http://example.com
maps to /public_html/
for its root, and I can't change this. I've added a mod_rewrite rule to handle this issue:
RewriteEngine On
RewriteRule ^$ example\.com/ [L]
RewriteRule (.*) example\.com/$1/ [L]
If I browse to http://example.com/subdir
(without the trailing /
) it will list file.jpg , but the URL for it will be http://example.com/file.jpg
. The parent directory link is http://example.com/example.com/
.
If I 开发者_运维技巧browse to http://example.com/subdir/
(with the trailing /
) it will list file.jpg with the proper URL: http://example.com/subdir/file.jpg
. However, the parent directory link is http://example.com/example.com/subdir/
.
I'm very confused for what's going on and I'd love any help on this.
(Note that if I take off the final /
in the mod_rewrite rule then going to http://example.com/subdir
without the /
will redirect to the http://example.com/example.com/subdir/
variant. Also, the parent directory for the listing at http://example.com/subdir/
changes to http://example.com/example.com/
, which is almost correct.)
This could be caused by a disabled DirectorySlash. So try to enable it or use this rule to do the same with mod_rewrite:
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .*[^/]$ %{REQUEST_URI}/ [L,R=301]
精彩评论