从与控制器共享名称的目录共享静态文件
我在一个项目中使用 kohana 3,并有一个控制器 /foo 和各种操作(/foo/about、/foo/features 等)。然而,最近我得到了几个文件夹,其中有一个相当大的 html 站点,可以放置在这个目录中,包括 html/txt/图片文件。我现在有一个看起来像这样的结构
- kohana/foo/help/index.html
- kohana/foo/help_de/index.html
- kohana/foo/help_es/index.html
等等。
但是,我的应用程序完美地提供了这些文件,当我转到 /foo 控制器时 - 它不再起作用。我可以通过编辑我的 htaccess 文件来解决这个问题:
RewriteRule ^(?:application|modules|system|foo)\b.* index.php/$0 [L]
但是,然后,我的静态文件不会得到服务。如果静态文件存在,我可以做什么来提供它们,但如果它们不存在,则默认返回到我的控制器/操作?
我一直在尝试编辑 htaccess 以仅提供文件夹列表中的文件,但无法找出执行此操作的正确方法。
如果我必须进行更多描述,请告诉我。
谢谢 -
编辑(完整的 .htaccess):
RewriteEngine On
RewriteBase /
<Files .*>
Order Deny,Allow
Deny From All
</Files>
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT]
I'm using kohana 3 for a project and have a controller /foo with various actions (/foo/about, /foo/features, et cetera). However, I was just recently given a couple folders with a fairly large html site to be placed within this directory including html/txt/picture files. I now have a structure that looks like this
- kohana/foo/help/index.html
- kohana/foo/help_de/index.html
- kohana/foo/help_es/index.html
and so on..
My application serves these files just perfectly, however, when I go to the /foo controller - it no longer works. I can solve this problem by editing my htaccess file to be as such:
RewriteRule ^(?:application|modules|system|foo)\b.* index.php/$0 [L]
However, then, my static files don't get served. What can I do to serve the static files if they exist but default back to my controller/actions when they don't?
I've been trying to edit the htaccess to only serve files from the list of folders but cannot figure out the proper way to go about doing this.
Please let me know if I must be more descriptive.
Thank you -
Edit (full .htaccess):
RewriteEngine On
RewriteBase /
<Files .*>
Order Deny,Allow
Deny From All
</Files>
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
/foo
链接被这一行破坏:因为
/foo
被视为一个目录。只要您不担心丢失目录索引,您就可以删除该行。The
/foo
link is being broken by this line:Because
/foo
is being seen as a directory. You could probably just remove that line, as long as you aren't worried about losing directory indexes.我不知道 kohana,但我想如果您在“RewriteEngine on”2 行之后添加 .htacess ,它就可以工作:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f #Exlude files
RewriteCond %{REQUEST_FILENAME} !-d #排除目录
这将从处理中排除文件和目录。
I dont know kohana, but I imagine it can work if you add in your .htacess after "RewriteEngine on" 2 lines:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f #Exlude files
RewriteCond %{REQUEST_FILENAME} !-d #Exlude directories
This will exclude files and directories from beign processed.