-2

可能重复:
如何从 cakephp 的 url 中删除操作名称?

我正在使用 cakephp 在 Cakephp 中开发我的网站,我想从应用程序 URL 中删除操作(或视图)名称我应该怎么做。我的要求是我想添加参数来代替视图名称最近我的 URL 是这样的:

“域名/控制器名/视图名/param1/param2”

但是我需要

“域名/控制器名/param1/param2”

我的 .htaccess 文件如下所示

.htaccess 在根文件夹中

<IfModule mod_rewrite.c>
   RewriteEngine on 
   RewriteRule    ^$     [L]
   RewriteRule    (.*) app/webroot/index.php/$1 [L]
</IfModule>

.htaccess 在应用程序文件夹中

 <IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteBase /liberty_new/app/
  RewriteRule    ^$    webroot/index.php/    [L]
  RewriteRule    (.*) webroot/index.php/$1    [L]
 </IfModule>

.htaccess 在 webroot 文件夹中

<IfModule mod_rewrite.c>
 RewriteEngine ON
 RewriteBase /
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^(.*)$ /$1 [QSA,L]
</IfModule>
4

1 回答 1

1

您在Config\routes.php文件中执行此操作。根据需要设置Router参数以编写 URL。不要编辑您的 htaccess 文件,否则它可能/将会破坏 CakePHP 路由。

Router::connect('/:controller/:param1/:param2', array('action' => 'index'), array('param1' => '[a-zA-Z0-9]+', 'param2' => '[a-zA-Z0-9]+'));

这应该将所有对任何控制器的请求发送到该控制器的索引函数并传递参数 1 和 2。当然,这可以进行大量定制。我强烈建议您阅读文档中有关路由的信息,除非必须,否则不要更改 htaccess。

http://book.cakephp.org/2.0/en/development/routing.html#routes-configuration

于 2012-12-28T13:19:48.397 回答