Host Cake 3 App in webserver's subDirectory


Hi everyone !

I have already tried, with no succes, to deploy a cake 3 app last summer.
But works duty oblige me to come back with the same problem !
My app works perfectly on built-in cake server and on WAMP server but not on my prod server.
Only difference is that I need to deploy my app in a subdirectory on my prod server.

So, Url from local server is : localhost:XXXX/MyApp
Now, my prod url is : server_host/sub/MyApp
Which not works

I have change app.php to use set “base” to “/sub/MyApp”, decommented “baseUrl” and set “FullBaseUrl” to “server_host/sub/MyApp”.

Also change my .htacces as described in many other topics like this :

root :

RewriteEngine on RewriteBase /sub/MyApp/ RewriteRule ^$ webroot/ [L] RewriteRule (.*) webroot/$1 [L]

root/webroot :

RewriteEngine On RewriteBase /sub/MyApp/webroot/ RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !^/(webroot/)?(img|css|js)/(.*)$ RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

Just note that I cannot change anything on the server itself and mod_rewrite is enable


What error do you get?


Oh yes sorry, with my changes, cake return an error saying “MySubDirectoryNameController” doesn’t exists.
Without any change, just got a 404.

But I finally found that when url rewriting is disabled, cake site is only accessible from url “root/webroot/index.php/ControllerName/action/param”, in my case : “host/sub/MyApp/webroot/index.php/MyController/MyAction/MyParam”.

It’s a bit awful but it works so I’ll continue with this…

Thanks anyway @rrd !


I think your mod rewrite is misconfigured or not working. I would suggest to check the rewrite log.


Arf it doesn’t suprise me but as I said, no changing can be done on the server itself (thanks to the sys admin :confused: ) so I’ll keep the ugly urls and check for correct rewrite rules if needed later.

Thanks again @rrd !