[英]How do I run a CakePHP app in a sub-folder from the root domain?
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
. 我正在尝试在子文件夹中设置CakePHP应用程序,但是从根域运行它,例如,用户请求
domain.co.uk
并且他们在{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: 托管设置不允许我更改文档根目录,因此我在根目录中有以下.htaccess:
<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
. 但是,Cake会检测子文件夹并将其添加到它创建的所有URL(例如,
$this->Form->create()
操作等),所以我最终将表单发布到domain.co.uk/version-13/signup
而不是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!
无论我尝试什么,我都无法让它发挥作用!
It's hard to understand your setup, you should explain it more. 很难理解你的设置,你应该解释一下。 But if I got it right, check /app/Config/core.php:
但如果我做对了,请检查/app/Config/core.php:
Configure::write('App.fullBaseUrl', 'http://example.com');
Change your RewriteBase /
to RewriteBase /version-13/
(in your .htaccess)and you should be set right up. 将你的
RewriteBase /
改为RewriteBase /version-13/
(在.htaccess中),你应该正确设置。
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. 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
http://cookingwithcakephp.blogspot.nl/2008/04/installing-cakephp-into-subdirectory.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.