4

I'm trying to setup a CakePHP app in a sub-folder but run it from the root domain, eg, user requests domain.co.uk and they get the webroot at {DOCUMENT_ROOT}/version-13/app/webroot.

The hosting setup doesn't allow me to change the document root so I have the following .htaccess in the root:

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

This appears to do the job. However, Cake detects the sub-folder and adds it to all the URLs it creates (eg, $this->Form->create() actions, etc) so I end up with forms posted to domain.co.uk/version-13/signup instead of domain.co.uk/signup.

I know this is probably going to be something simple but I'm hitting a brick wall. No matter what I try I can't get it to work!

Tom
  • 224
  • 4
  • 14
  • Why are you uploading your versions in different locations? Have you looked into [version control](http://en.wikipedia.org/wiki/Revision_control)? For example: [git](http://git-scm.com/) or [subversion](http://subversion.apache.org/)? – Jelmer Oct 02 '13 at 23:05
  • I'm using Git for versioning, this is more for the deployment. I'm limited with what I can do on this host (and don't have the option of a VPS) so the idea is I can `git archive master`, upload the new version into a separate folder, do the testing then switch the paths for a zero downtime upgrade. – Tom Oct 03 '13 at 08:19
  • Ah okay. Sounds creative :) – Jelmer Oct 03 '13 at 20:08

2 Answers2

3

It's hard to understand your setup, you should explain it more. But if I got it right, check /app/Config/core.php:

Configure::write('App.fullBaseUrl', 'http://example.com');
  • 1
    Setting this option didn't have any effect. However, I noticed that setting `Configure::write('App.baseUrl, '/');` did. It now works as expected - all generated URLs don't have the version folder prefixed. Thanks! – Tom Oct 03 '13 at 08:36
0

Change your RewriteBase / to RewriteBase /version-13/ (in your .htaccess)and you should be set right up.

I had the exact same issue when I didn't have my local server set up correctly, which forced me to put my applications in a folder of my main domain.

Please note that you can have multiple apps at one core. This could be useful for you "versioning".

Ps. after a quick Google search I found the following. Didn't read it that well, but it looks like it does the same. http://cookingwithcakephp.blogspot.nl/2008/04/installing-cakephp-into-subdirectory.html

Jelmer
  • 2,663
  • 2
  • 27
  • 45
  • Thanks, I tried your suggestion (and the ones from the linked article - I was actually there before I posted here!). Setting the RewriteBase to the version folder worked just the same - the pages respond correctly to the routes in routes.php but generated URLs (eg, ones for forms) include the sub-folder (eg, `
    `).
    – Tom Oct 03 '13 at 08:29
  • Why shouldn't it have to include the sub-folder in a form? You want it to go to `/version-13/signup` right? Otherwise it is going to `/signup` which does not exist if I understand you correctly. – Jelmer Oct 03 '13 at 20:07
  • `/signup` is the route I connected in routes.php - it's a "pretty url" so I don't have the default `/{controller}/{action}` format. If the site is not in a sub-folder, any form I generate with `$this->Form->create()` POSTs to `/signup`. However, when in the sub-folder, I can see the page at `/signup` but all generated URLs include the sub-folder. I want the site to work as though there is no sub-folder and behave as though it's in the root. Setting `Configure::write('App.baseUrl, '/');` did the trick. – Tom Oct 04 '13 at 09:24