3

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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Domas
  • 1,133
  • 4
  • 18
  • 46
  • just move the contents of cake_app one folder up. The "many examples" you've already found all still apply. Also note that this question probably means you're using a development style install - [you shouldn't be doing that](http://book.cakephp.org/3.0/en/installation.html#production). – AD7six Oct 08 '15 at 14:06
  • The reason why I do not want to move it one folder up is that I have a wordpress install in the root. Thanks for the install link. – Domas Oct 08 '15 at 14:14
  • 1
    That's a rather significant detail to omit - please edit the question and indicate which urls should be rewritten and which not. In the absence of information right now you've got a logical conflict. – AD7six Oct 08 '15 at 14:17
  • Thank you for guiding, just updated the question. – Domas Oct 08 '15 at 14:42

1 Answers1

3

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']);
Salines
  • 5,674
  • 3
  • 25
  • 50