使用mod_rewrite和apache2redirect和别名相同的url?

基本上,我主持一个静态的HTML网站,我需要:

  1. http://example.com/some-direcory/index.html
    被redirect到:
    http://example.com/some-direcory

  2. 虽然仍然有物理文件代表的内容存储在:
    http://example.com/some-direcory/index.html

这是我有:

 # rewrite /dir/file to /dir/file/index.html RewriteRule ^([\w\/-]+)(\?.*)?$ $1/index.html$2 [L,T=application/x-httpd-html] 

这似乎对我上面的#2需求很好,然后我有这个满足我对#1的需求:

 # rewrite /dir/file/index.html to /dir/file RewriteRule ^(.*)/index\.html$ /$1 [R=301,L,C] 

但是,当我将这两个规则结合在一起时,他们显然会创build一个redirect循环 有什么办法可以解决吗?

 RewriteCond "%{THE_REQUEST}" "\s(/[\w/-]+?)/index\.html[?\s]" RewriteRule "^" "%1" [R=301,L,C] RewriteCond "%{DOCUMENT_ROOT}/$1/index.html" -f RewriteRule "^([\w/-]+[^/])$" "/$1/index.html" [L,T=application/x-httpd-html] 

请注意DirectorySlash可能的问题。