【问题标题】:how to change URLs in cakephp through .htaccess如何通过 .htaccess 更改 cakephp 中的 URL
【发布时间】:2010-11-16 09:16:22
【问题描述】:

我正在使用 cakephp 1.3,我希望用户不要看到传统的蛋糕 php 网址,例如:

sitename.com/users/contact,而不是我想使用 .htaccess 来 mod_rewrite 并生成漂亮的 URL,例如:sitename.com/contact。

如何使用 cake phps .htaccess 来做到这一点。

【问题讨论】:

    标签: .htaccess cakephp


    【解决方案1】:

    使用 .htaccess 重写规则将毫无意义,因为 Cake 仍会以“Cake 方式”生成所有链接,完全不会注意到任何重写的 URL。

    改为使用Routes 为某些操作配置特殊的 URL。这些将是可反向路由的,这意味着您告诉 Cake 为array('controller' => 'foo', 'action' => 'bar') 创建链接的任何地方,它将使用配置的短路由。示例:

    Router::connect('/foo', array('controller' => 'foo', 'action' => 'bar'));
    
    echo $html->link('FooBar', array('controller' => 'foo', 'action' => 'bar'));
    // <a href="/foo">FooBar</a>
    

    【讨论】:

      猜你喜欢
      • 2012-12-10
      • 1970-01-01
      • 1970-01-01
      • 2015-03-06
      • 1970-01-01
      • 1970-01-01
      • 2015-01-10
      • 2014-04-01
      • 2015-04-10
      相关资源
      最近更新 更多