mod_rewrite /dir/index.html到/ dir /

时间:2013-04-12 11:57:03

标签: .htaccess mod-rewrite

如何使用htaccess自动更改:

/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)

文件index.html实际存在于目录

1 个答案:

答案 0 :(得分:0)

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

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