title: Router Configuration CakePHP Remove Pages in URL
body: <p>I'm currently looking for a solution to remove "Pages" from the URL but not make it hard to add a controller.</p>
  
  <p>I looked around and searched on Google for a solution, but the best solution they could give was this:</p>
  
  <pre><code>Router::Connect('/*', array('controller' =&gt; 'pages', 'action' =&gt; 'display'));
  </code></pre>
  
  <p><a href="http://bakery.cakephp.org/articles/joelstein/2007/05/02/taking-advantage-of-the-pages-controller" rel="nofollow">Example Link</a></p>
  
  <p>But the problem with this solution is that every time I want to add a controller I need to add the following lines toe my <em>config/routers.php</em> file</p>
  
  <pre><code>Router::Connect('/Users/:action/, array('controller' =&gt; 'Users');
  Router::Connect('/users/:action/, array('controller' =&gt; 'Users');
  </code></pre>
  
  <p>The reason why I added these two lines is because I didn't want the URL to be case sensitive.</p>
  
  <p>I also know that it doesn't happen that often, once the website is "FINISHED", that the controllers are being changed.</p>
  
  <p>So my solution was the following:</p>
  
  <pre><code>/*
   * Get URL
   * Seperate in array
   * Remove empty elements
   */
  $url = array_filter(explode("/", Router::url()));
  
  /*
   * Get Controllers list
   */
  $Controllers = App::objects('controller');
  $CleanControllers = array();
  
  /*
   * Remove string 'Controller' from element
   * lower string
   */
  foreach($Controllers as $Controller) {
      $CleanControllers[] = strtolower(str_replace('Controller', '', $Controller));
  }
  
  /*
   * Check if first element, from URL, is NOT a controllers array
   */
  if(!in_array(strtolower(reset($url)), $CleanControllers)) {
      /*
       * Forward to "Pages" controller 
       */
      Router::connect('/', array('controller' =&gt; 'Pages', 'action' =&gt; 'display', 'home'));
      Router::connect('/*', array('controller' =&gt; 'Pages', 'action' =&gt; 'display'));
  }
  
  /*
   * Check if first element, from URL, is NOT a controllers array
   */
  
  CakePlugin::routes();
  
  require CAKE . 'Config' . DS . 'routes.php';
  </code></pre>
  
  <p>So my question is this solution a performance KILLER? If so, does anyone know a better solution?</p>
  
  <p>Because when I looking at the advanced routing from CakePHP, it seems to me that I need a SUPER Advanced routing... Or I simply don't understand it.</p>
  
  <p>CAKEPHP Version 2.1</p>
  
  <p>Thanks for your help!</p>