Trying to remove /events/view/ from url

I am using cakePhp 2.8.2. I am not sure where to start here. I have read about using the routes.php to be able to remove the /events/view/ part of the URL but not sure if this is as simple as it’s made out to be and also the .htaccess file.

The url string looks like this in my test project:


and I am trying to do this:


my .htaccess is:

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

My routes.php is like this:

if (!file_exists(APP.'Config'.DS.'database.php')) {
Router::connect('/*', array('plugin' => 'install' ,'controller' => 'install'));

Router::connect('/', array('controller' => 'events', 'action' => 'index'));
Router::connect('/about', array('plugin'=>null, 'controller' => 'pages', 'action' => 'display', 'about'));

Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));

Router::connect('/tests', array('controller' => 'tests', 'action' => 'index'));

Router::connect('/admin', array('admin' => true, 'controller' => 'settings', 'action' => 'dashboard'));

Router::connect('/feeds/*', array('controller' => 'feeds', 'action' => 'index'));

Router::connect('/lang/*', array('controller'=>'settings', 'action'=>'lang'));


require CAKE . 'Config' . DS . 'routes.php';

Any help with this would be welcome, also if it’s not possible a confirmation it is not possible would also stop me from searching everywhere.

I should add that my ‘Events’ folder with’view.ctp’ is contained in the ‘View’ folder which is contained in the’app’ folder.

Why not template folder, then it wouldn’t show. In other words, view in Template folder, and make a layout under Layout folder to display it.

Not sure what you mean here. I think it’s not possible to just remove the /events/view/ so I am thinking of trying to rename them /e/v/ how is that possible?

Have you tried to put you view in the template folder, and make a layout file. Use proper naming conventions, and all should display just fine. See the blog tutorial part 2

<!-- File: src/Template/Articles/index.ctp -->

<h1>Blog articles</h1>

    <!-- Here is where we iterate through our $articles query object, printing out article info -->

    <?php foreach ($articles as $article): ?>
        <td><?= $article->id ?></td>
            <?= $this->Html->link($article->title, ['action' => 'view', $article->id]) ?>
            <?= $article->created->format(DATE_RFC850) ?>
    <?php endforeach; ?>

the view is in templates
Then read the docs on layouts something like

<!DOCTYPE html>
<html lang="en">
<title><?= h($this->fetch('title')) ?></title>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<!-- Include external files and scripts here (See HTML helper for more info.) -->
echo $this->fetch('meta');
echo $this->fetch('css');
echo $this->fetch('script');

<!-- If you'd like some sort of menu to
show up on all of your views, include it here -->
<div id="header">
    <div id="menu">...</div>

<!-- Here's where I want my views to be displayed -->
<?= $this->fetch('content') ?>   //////////////THIS IS DISPLAYING THE VIEW////////////////////

<!-- Add a footer to each displayed page -->
<div id="footer">...</div>


Hi Jim,

Thanks for trying to help. The issue is to do with the routes.php I have done a simple fix by renaming the /view/ file but don’t know how to do the /events/ part which is the controller.

Don’t worry about it.

you cane it anything you want in routes like

$routes->connect('/dog/doglist/', ['controller' => 'Dogs', 'action' => 'dogList']);

could be changed to

$routes->connect('/happyzappy/', ['controller' => 'Dogs', 'action' => 'dogList']);

then mysite/happyzappy would show the doglist.

Ha! ha! thanks for that it made me laugh.

Seriously let me see if I can get that to work and come back again.

Appreciate the humour, let’s see if it will work for me now…


Ok that’s not what I want.

$routes->connect('/dog/doglist/', ['controller' => 'Dogs', 'action' => 'dogList']);

I want the /dog/ name changed.

My set up is root folder with app.

then when I go to the webpage it shows the site name

But when I trigger a link it would be

I want the routes to make the URL show: