Grockell
Grockell

Reputation: 35

Cakephp 3.x trying to view Uploaded images results in Missing Controller Error

I have an image located at webroot/uploads/profiles/partner_1/bg_image.jpg

When I attempt to display an uploaded image located at: uploads/profiles/partner_1/bg_image.jpg

I get the Error:

Error: UploadsController could not be found.

What makes this particularly frustrating is that this same application is working on my local dev server, and only fails when I move it up to production. I feel like there must be some simple solution that I'm just missing as I stress over deadlines.

The .htaccess file is unmodified but follows:

# Uncomment the following to prevent the httpoxy vulnerability
# See: https://httpoxy.org/
#<IfModule mod_headers.c>
#    RequestHeader unset Proxy
#</IfModule>

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule    ^$    webroot/    [L]
    RewriteRule    (.*) webroot/$1    [L]
</IfModule>

I experimented placing the target file in different directories down the path.. It seems to be a factor of directory depth.

I can find the file in: /uploads, /uploads/profiles, /img, /img/uploads,

Basically anything more then 2 directories deeper then webroot fails.

Upvotes: 0

Views: 387

Answers (1)

Reactgular
Reactgular

Reputation: 54781

You have no condition in your rewrite rule to exclude existing files.

<IfModule mod_rewrite.c>
     RewriteEngine On
     RewriteCond %{REQUEST_FILENAME} !-f
     RewriteRule ^ index.php [L]
</IfModule>

I don't recognise your .htaccess file as anything from any previous release of CakePHP. That doesn't mean it's wrong, but all releases have rewritten the URL to the index.php file.

Upvotes: 1

Related Questions