我有一个网站,在某些文件夹中预先存在index.php文件。作为推动网站更加动态的一部分,以及从集中索引文件路由的一部分。如果在该目录中找不到索引(php|htm|html),我希望我的网站上的所有子目录都重写到根index.php。
--+ /
| /index.php
+--+
| + /subdir1
|
|--+
| /subdir2
+ /subdir2/index.php
因此,subdir1将使用根index.php,但subdir2将使用其目录中的index.php文件。
我使用了一个后备资源,因为这正是我想要的:
#Use root index.php
FallbackResource /index.php
然而,我发现当我使用它时,我会收到以下错误消息。
Failed to load resource: net::ERR_INCOMPLETE_CHUNKED_ENCODING
所以我又回到了老版本:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [NC,QSA,L]
但我不确定如何排除已经存在索引文件的子目录。
^!/index'.(php|htm|html)
是这样的吗?
您可以在root.htaccess:中使用此规则
DirectoryIndex index.html index.htm index.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/$1/index'.html !-f
RewriteCond %{DOCUMENT_ROOT}/$1/index'.htm !-f
RewriteCond %{DOCUMENT_ROOT}/$1/index'.php !-f
RewriteRule ^(.+?)(?:/[^/]+)?/?$ index.php [L]