php mod rewrite .htaccess ignore directory


php mod rewrite .htaccess ignore directory

我应该设置什么规则,才能使mod_rewrite完全忽略目录"public"?我的意思是,文件应该可以在其中访问,但如果文件不存在,服务器错误页面应该提出类似禁止或文件未找到的东西。我不需要自定义错误页面或类似的东西。我只是希望"公众"表现得像根本没有mod_rewrite。

这是我的.htaccess文件:

RewriteEngine on
RewriteCond $1 !^(index'.php|robots'.txt)
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

我的文件结构是

/system/
/application/
/public/

我希望文件夹公共的行为,就像根本没有设置重写规则一样,完全忽略它。

编辑

那是我的.htaccess文件:

RewriteEngine on
RewriteRule ^(public)($|/) - [L,NC]
RewriteCond $1 !^(index'.php|robots'.txt)
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

我已经在/public/文件夹中有这个 .htaccess:

RewriteEngine off

我已经尝试了上面的所有不同答案(以及来自谷歌的大量答案)。我试图把它们混在一起。

我的文件夹:

/system/
/application/
/public/ 
/public/.htaccess #RewriteEngine off
/public/favicon.ico
/index.php

以下是我得到的结果的网址:

/public/favicon.ico -> I get the favicon
/public/faviDon.ico -> I get the index.php (without mod rewrite you would get "not found")
/public/ -> I get the index.php (without mod rewrite "forbidden")

因此,如果未找到文件或直接访问文件夹,它仍然会重写 url。

你能看到吗?

非常感谢你们的努力!我真的很感激!

编辑

我在我的机器上完全设置了你的文件

//  /.htaccess
RewriteEngine on
RewriteRule ^(public)($|/) - [L,NC]
RewriteCond $1 !^(index'.php|robots'.txt)
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

公用文件夹中的 .htaccess :

//  /public/.htaccess
Options -Indexes
RewriteEngine off

这将禁用您想要的重写。

/public/                 -> 403 Forbidden
/public/favicon.ico      -> 200 File found
/public/not-existing.ext -> 404 File not found

您的公用文件夹中是否有索引.php?也许你可以删除那个..

您在哪种机器上进行测试?

我在Linux + Apache 2 + PHP5.3上测试了它

我可以在下午给你更多的支持(我的时间+格林威治标准时间+2

编辑 2

当我从/.htaccess 中删除此行仍然有效时

RewriteRule ^(public)($|/) - [L,NC]

一切都由公用文件夹中的 .htaccess 处理。

也许这是浏览器中的缓存问题。尝试使用其他浏览器/清理历史记录/安装应用程序以删除缓存。(取决于您使用的浏览器)