dongruo4601
2017-11-09 11:47
浏览 13
已采纳

Cakephp网址链接

I want to make all my pages/urls seo friendly including the dynamic ones but i'm stuck at it.

I made it work for the static pages for example :

$routes->connect('/:lang/about',['controller' => 'Pages', 'action' => 'about'] ); 

But when i add the following to routes

$routes->connect('/:lang/:slug',['controller' => 'MyController', 'action' => 'index'], ['pass' => ['slug']] ); 

All the pages redirect to MyController even the static ones, so i'm wondering if there is any solution to that one.

Thanks.

图片转代码服务由CSDN问答提供 功能建议

我想让我的所有页面/网址都很友好,包括动态的,但我坚持不懈。< / p>

我使其适用于静态页面,例如:

  $ routes-&gt; connect('/:lang / about',  ['controller'=&gt;'Pages','action'=&gt;'about']);  
   
 
 

但是当我向路线添加以下内容时

  $ routes-&gt; connect('/:lang  /:slug',['controller'=&gt;'MyController','action'=&gt;'index'],['pass'=&gt; ['slug']]);  
   
 
 

所有页面都重定向到MyController,甚至是静态页面,所以我想知道是否有任何解决方案。

谢谢。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duandi2853 2017-11-09 11:59
    已采纳

    "catch-all" routes (like the one in your question) need to go after other routes. This way the static routes are checked first and "catch-all" are used only when no other routes were matched

    For example:

    $routes->connect('/:lang/about',['controller' => 'Pages', 'action' => 'about'] );
    $routes->connect('/:lang/:slug',['controller' => 'MyController', 'action' => 'index'], ['pass' => ['slug']] );
    

    Instead of (notice the ordering):

    $routes->connect('/:lang/:slug',['controller' => 'MyController', 'action' => 'index'], ['pass' => ['slug']] );
    $routes->connect('/:lang/about',['controller' => 'Pages', 'action' => 'about'] );
    
    点赞 评论

相关推荐 更多相似问题