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

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.

  • 写回答

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'] );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Stata 面板数据模型选择
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用