Rewriting cakephp path in cakephp 3.0

2019-06-26 03:22发布

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.

1条回答
贪生不怕死
2楼-- · 2019-06-26 03:55

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']);
查看更多
登录 后发表回答