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

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

问题描述

我需要从网址中移除应用程式资料夹。
示例URL是: mydomain.com/cake_app/vechicles/add
我需要的是 mydomain.com / vechicles / add



注意!在mydomain.com的根目录下,我有一个WordPress安装程序运行,所以如果URL中有一个 vechicles 控制器名,我只需要将用户路由到蛋糕应用程序。 p>

我已经找到许多例子,如何通过.htaccess文件,但这些是为CakePHP< 3.0,似乎无法使用当前版本。


解决方案

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

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

UPDATE



< blockquote>

注意!在mydomain.com的根目录下,我有一个WordPress安装程序运行,所以如果URL中有一个 vechicles 控制器名,我只需要将用户路由到蛋糕应用程序。 p>

在任何wordpress规则之前,将此规则添加到.htaccess中。

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

现在mydomain.com/vechicles/显示您的cake_app。



Router :: connect('/ add',array('controller'=>'vechicles','action'=>'add'));



CakePHP 3

  $ routes-& ,['controller'=>'vechicles','action'=>'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

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.

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.

Any help or guidance for how to achieve it is much apprreciated.

解决方案

Add .htaccess to your domain root folder:

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

UPDATE

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.

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>

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

CakePHP 2

Router::connect('/add', array('controller' => 'vechicles', 'action' => 'add') );

CakePHP 3

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

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

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