【发布时间】:2013-01-23 19:52:35
【问题描述】:
我应该设置什么规则,让 mod_rewrite 完全忽略目录“public”? 我的意思是,文件应该可以在其中访问,但如果文件不存在,服务器错误页面应该会出现类似“禁止”或“未找到文件”之类的信息。我不需要自定义错误页面或类似的东西。我只是想让“公众”表现得像根本没有 mod_rewrite 一样。
这是我的 .htaccess 文件:
RewriteEngine on
RewriteCond $1 !^(index\.php|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
我的文件结构是
/system/
/application/
/public/
我希望文件夹 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。
你能看吗?
非常感谢你们的努力!对此,我真的非常感激!
【问题讨论】:
-
更适合 serverfault.com
-
如果“public”是网络根目录,那么就您网站的网址而言,它会被“忽略”。
标签: php .htaccess mod-rewrite