2013-04-12 34 views
-1

如何自动与htaccess的这种变化:mod_rewrite的/dir/index.html到/ DIR/

文件的index.html

/dir1/index.html -> /dir1/ (with 301 redirect) 
/dir1/subdir1/index.html -> /dir1/subdir1/ (with 301 redirect) 
... 
/another_dir/index.html -> /another_dir/ (with 301 redirect) 
/another_dir/another_subdir1/index.html -> /another_dir/another_subdir1/ (with 301 redirect) 

等物理上的目录存在

回答

0
RewriteCond %{REQUEST_FILENAME} -f 
RewriteRule ^(.*)/index\.html$ /$1/ [R=301,L] 

此代码将重定向以index.html(其中文件实际存在)结束的所有内容。

+0

此构造不支持子装订器和 /another_dir/another_subdir1/index.html将更改为/ another_subdir1/ – user2274259

+0

它应该工作,因为'。*'捕获组包含正斜杠。你试过了吗?你的'.htaccess'文件在哪里? –

+0

我htaccess的 AddDefaultCharset UTF-8 RewriteEngine叙述在 的RewriteCond%{REQUEST_FILENAME} -f 重写规则^(。*)/索引\ html的$ $ 1/[R = 301,L] – user2274259