简体   繁体   English

Cakephp从网址中删除蛋糕

[英]Cakephp removing cake from url

I have the following site My domain 我有以下网站我的域

As you can see if you click the link you will get an error!. 如您所见,如果您单击链接,您将得到一个错误!。

Now if you instead add cake/users/login to the end of the url you will go to the correct site. 现在,如果您改为在网址末尾添加cake / users / login,则将转到正确的站点。

Now my question is how do i remove cake from the url and how do set a default controller ? 现在我的问题是如何从网址中删除蛋糕,以及如何设置默认控制器? (so that if a path is not found it will go to that controllers index action instead?) (因此,如果找不到路径,它将转至该控制器的索引操作?)

Since the CakePHP is based on relative paths, the only thing you can do is to move the contents of cake folder with one level up. 由于CakePHP基于相对路径,因此您唯一可以做的就是向上移动Cake文件夹的内容。

As example if you have server path like: /var/www and in it you have /var/www/cake all you need to do is to move contents of cake folder to /var/www the path could depend from the server configuration but the principle is the same. 例如,如果您具有服务器路径,例如:/ var / www,并且其中具有/ var / www / cake,则您需要做的就是将Cake文件夹的内容移动到/ var / www,该路径可能取决于服务器配置,但是原理是一样的。 I don't think you should make some changes in the configs. 我不认为您应该在配置中进行一些更改。

On the second question how to set default controller for home page - it would be there by default, but I guess you have removed it: go to app/Config/routes.php of your project and see is there a row starting with 关于第二个问题,如何为主页设置默认控制器-默认情况下会存在,但我想您已将其删除:转到项目的app / Config / routes.php并查看是否有一行以

Router::connect( '/', ...);

if you dont have it, add it like: 如果您没有它,请像这样添加它:

Router::connect( '/', array('controller' => 'your_controller', 'action' => 'index') );

The file /app/config/routes.php contains the routing configuration, and default action can be changed there. 文件/app/config/routes.php包含路由配置,可以在此处更改默认操作。 Eg, 例如,

Router::connect( '/pages', array('controller' => 'pages', 'action' => 'display') ); 路由器:: connect('/ pages',array('controller'=>'pages','action'=>'display')));

It is the problem of .htaccess, cakephp have th .htaccess 这是.htaccess的问题,cakephp有.htaccess

/.htaccess /app/.htaccess /app/webroot/.htaccess /.htaccess /app/.htaccess /app/webroot/.htaccess

you have to add below code after RewriteEngine on 您必须在RewriteEngine之后添加以下代码

RewriteBase /cake/                 in /.htaccess
RewriteBase /cake/app/             in /app/.htaccess
RewriteBase /cake/app/webroot/     in /app/webroot/.htaccess

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM