Apache htaccess重定向子目录,index.php除外

Apache htaccess重定向子目录,index.php除外,apache,mod-rewrite,url-rewriting,Apache,Mod Rewrite,Url Rewriting,我在www.mydomain.com/dir中有一个htaccess文件 我想将请求从www.mydomain.com/dir/*重定向到www.mydomain.com/dir,但www.mydomain.com/dir/index.php除外 我试过这个: RewriteEngine on RewriteCond DOCUMENT_ROOT/ !-f RewriteRule ^/*$ index.php 我做错了什么?这可能会起作用: Options +FollowSymLinks -Mu

我在www.mydomain.com/dir中有一个htaccess文件

我想将请求从www.mydomain.com/dir/*重定向到www.mydomain.com/dir,但www.mydomain.com/dir/index.php除外

我试过这个:

RewriteEngine on
RewriteCond DOCUMENT_ROOT/ !-f
RewriteRule ^/*$ index.php

我做错了什么?

这可能会起作用:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /dir/

RewriteRule (?!^index\.php$)^.+$ index.php [L,NC]
这几乎奏效了

www.mydomain.com/dir/.htaccess:

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /dir/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (?!^index\.php$)^.+$ index.php [L,NC]

但当我访问dir中的任何文件或子目录时,我得到404。index.php位于dir中,任何对dir中的文件或子目录的请求都应重定向到dir/index.php。

从www.mydomain.com/dir/*到www.mydomain.com/dir的请求是什么意思?对www.mydomain.com/dir/*的请求应重定向到www.mydomain.com/dir。我不想访问“dir”的子目录。