从与控制器共享名称的目录共享静态文件

发布于 2024-10-16 11:27:45 字数 960 浏览 4 评论 0原文

我在一个项目中使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

佼人 2024-10-23 11:27:45

/foo 链接被这一行破坏:

RewriteCond %{REQUEST_FILENAME} !-d

因为 /foo 被视为一个目录。只要您不担心丢失目录索引,您就可以删除该行。

The /foo link is being broken by this line:

RewriteCond %{REQUEST_FILENAME} !-d

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.

酒浓于脸红 2024-10-23 11:27:45

我不知道 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文