本文介绍了在cakephp 3.0中重写cakephp路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从URL中删除应用程序文件夹。
示例URL是: mydomain.com/cake_app/vechicles/add
我需要的是 mydomain.com / vechicles / add

I have a need to remove the app folder from the URL.Example URL is: mydomain.com/cake_app/vechicles/addWhat I need to have instead is mydomain.com/vechicles/add

注意!在mydomain.com的根目录中,我正在运行WordPress安装,因此,如果URL中有 vehicles 控制器名称,则仅需要将用户路由到Cake应用程序。

NOTE! In the root of mydomain.com I have a WordPress installation running, so I only need to route users to cake application if there is a vechicles controller name in the URL.

我已经找到了许多如何通过.htaccess文件执行此操作的示例,但这些都是针对CakePHP

I have found many examples for how to do it via .htaccess files, but these were for CakePHP <3.0 and seem not to work with the current version.

推荐答案

将.htaccess添加到您的域根文件夹:

Add .htaccess to your domain root folder:

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

更新

注意!在mydomain.com的根目录中,我正在运行WordPress安装,因此,如果URL中有 vehicles 控制器名称,则仅需要将用户路由到Cake应用程序。

在任何WordPress规则之前在.htaccess中添加此规则。

Add this rule in .htaccess before any of wordpress rules.

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

现在mydomain.com/vechicles/显示您的cake_app。内部Cake App进行路由

Now mydomain.com/vechicles/ show your cake_app. Inside cake app make routing

CakePHP 2

路由器:: connect('/ add',array('controller'=>'vechicles,'action'=>'add'));

CakePHP 3

$routes->connect('/add', ['controller' => 'vechicles', 'action' => 'add']);

这篇关于在cakephp 3.0中重写cakephp路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 13:41