Search code examples
apachecakephp

Understanding how CakePHP 3 is serving static images


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.


Solution

  • 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>