英文:
Understanding how CakePHP 3 is serving static images
问题
我有一张图片位于webroot/uploads/files
文件夹中。这张图片由CakePHP静态提供。我试图更好地理解如何控制这个机制。我已经从我的应用程序和插件中删除了$routes->fallbacks(DashedRoute::class);
的每个出现。因此,我的应用程序目前无法正常运行。然而,静态图片仍在提供。
我应该在哪里查找以防止提供静态图片?一旦我禁用它,我打算尝试创建一个控制器来更精细地控制它。
英文:
I have an image located in the webroot/uploads/files
folder. This image is being served statically by CakePHP. I am trying to better understand how to control this mechanism. I have removed every occurrence of $routes->fallbacks(DashedRoute::class);
from my app and plugins. My app therefor currently does not function. However, the static images are still being served.
Where should I be looking next to prevent the serving of static images? Once I have disabled it, I am going to try and create a controller to take care of it with more fine-grain control.
答案1
得分: 0
CakePHP不提供这些图像的服务。相反,它们由Apache web服务器提供。可以通过在适当的.htaccess文件中使用条目来停用这些图像的服务。
在我的情况下,我将以下代码添加到了CakePHP应用程序中webroot文件夹中的.htaccess文件中,该文件位于默认的Apache /var/www/html/目录结构中。
我使用以下代码停用了图像服务:
<Directory /var/www/html/app/webroot/uploads/files>
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^.*$ - [R=404,L]
</IfModule>
</Directory>
英文:
CakePHP is not serving these images. Instead they are being served by the Apache web server. The serving of these images can be deactivated by making use of of entries in the appropriate .htaccess file.
In my case I added the following code to the .htaccess file in the webroot folder inside of my CakePHP app, which is located in the default Apache /var/www/html/ directory structure.
I deactivated image serving with the follow code:
<Directory /var/www/html/app/webroot/uploads/files>
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^.*$ - [R=404,L]
</IfModule>
</Directory>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论