title: CakePHP: Redirect in routes.php
body: <p>OK, I dont know if I am taking the wrong approach or not but am stuck here...</p>
  
  <p>We have developed our website and we have many controllers expecting ids and special variables, links already redirecting to the controllers passing what is expected.</p>
  
  <p>The new requirement is to use <strong>friendlyUrls</strong> and the idea is that instead of having:</p>
  
  <blockquote>
    <p><a href="http://domain.com/search/advanced/term:head/city:/set:show-all/sort:basic-relevance" rel="nofollow">http://domain.com/search/advanced/term:head/city:/set:show-all/sort:basic-relevance</a></p>
  </blockquote>
  
  <p>it now reads</p>
  
  <blockquote>
    <p><a href="http://domain.com/search/head" rel="nofollow">http://domain.com/search/head</a></p>
  </blockquote>
  
  <p>or passing options.</p>
  
  <blockquote>
    <p><a href="http://domain.com/search/in-edinburgh-scotland/by-rating/head" rel="nofollow">http://domain.com/search/in-edinburgh-scotland/by-rating/head</a></p>
  </blockquote>
  
  <p>My idea was to, at the beginning of the Routes.php have a simple if such as:</p>
  
  <pre><code>    $friendlyUrl = $_SERVER['REQUEST_URI'];
      $friendlyUrl = split('/', $friendlyUrl);
      foreach ($friendlyUrl as $key =&gt; $params) {
          if(empty($params)){
              unset($friendlyUrl[$key]);
          }
          if($params == 'search'){
             Router::connect('/search/*', array('plugin'=&gt;'Search','controller' =&gt; 'Search', 'action' =&gt; 'advancedSearch', 'term'=&gt;'head));
  
          }elseif ($params == 'employers') {
              # code...
          }elseif ($params == 'employer-reviews') {
              # code...
          }elseif ($params == 'jobs') {
              # code...
          }
      }
  </code></pre>
  
  <p>That didn't work, then I tried adding something similar in my <strong>AppController</strong> and nothing.</p>
  
  <p>All in all the the thing that has to do is:</p>
  
  <ul>
  <li>Url be in the format of: /search/{term}</li>
  <li>Actually be redirecting to: /search/advanced/{term}/city:{optional}/set:show-all/sort:basic-relevance</li>
  <li>URL bar to keep reading: /search/{term}</li>
  </ul>
  
  <p>Anyone has an idea?! Thank you</p>