在cakephp 3.0中重写cakephp路径 [英] Rewriting cakephp path in cakephp 3.0

查看:112
本文介绍了在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/add What 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 <3.0的,似乎不适用于当前版本。

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应用程序。

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.

在任何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路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆