Rewriting cakephp path in cakephp 3.0

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.

Read More

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.

Related posts

1 comment

  1. 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']);
    

Comments are closed.