Apache 将对目录的请求(不带尾随斜杠)重写为index.php in.htaccess

Apache 将对目录的请求(不带尾随斜杠)重写为index.php in.htaccess,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,我看到过类似的请求,但无法找到一个有效的、快速的答案。基本上,我希望在内部将对目录(其中请求的URL不包含尾随斜杠)的请求重写为该目录中包含的index.php: http://example.com/foo => http://example.com/foo/index.php DirectorySlash On Options +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine On RewriteBase

我看到过类似的请求,但无法找到一个有效的、快速的答案。基本上,我希望在内部将对目录(其中请求的URL不包含尾随斜杠)的请求重写为该目录中包含的index.php:

http://example.com/foo => http://example.com/foo/index.php
DirectorySlash On
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} -d
RewriteRule (?!^.+?/$)^(.+)$ /$1/index.php [L]

现在,如果向apache发出请求,将执行一个外部可见的301重定向到,这将导致index.php被呈现,但是我想避免这种外部重定向和额外请求。

通过
httpd.conf
启用mod_rewrite和.htaccess,然后将此代码放在
文档根目录下的
.htaccess
中:

http://example.com/foo => http://example.com/foo/index.php
DirectorySlash On
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} -d
RewriteRule (?!^.+?/$)^(.+)$ /$1/index.php [L]