可能的重复:
如何从 cakephp 中的 url 中删除动作名称?
我正在使用 cakephp 在 Cakephp 中开发我的网站,我想从应用程序 URL 中删除操作(或视图)名称,我应该怎么做.我的要求是最近我想添加参数来代替视图名称,我的 URL 如下所示:
I am using cakephp to develop my website in Cakephp and I would like to remove action(or view )name from the application URL what should I do fro that. My requirement is I want to add the parameters in place of view name recently my URL is like:
域名/控制器名/视图名/param1/param2"
"domainname/controllername/viewname/param1/param2"
但我需要
域名/控制器名/param1/param2"
"Domainname/controllername/param1/param2"
我的 .htaccess 文件如下
My .htaccess files are like below
根文件夹中的.htaccess
.htaccess in root folder
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ [L]
RewriteRule (.*) app/webroot/index.php/$1 [L]
</IfModule>
.htaccess 在应用程序文件夹中
.htaccess in app folder
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /liberty_new/app/
RewriteRule ^$ webroot/index.php/ [L]
RewriteRule (.*) webroot/index.php/$1 [L]
</IfModule>
.htaccess 在 webroot 文件夹中
.htaccess in webroot folder
<IfModule mod_rewrite.c>
RewriteEngine ON
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /$1 [QSA,L]
</IfModule>
您在 Config
outes.php
文件中执行此操作.设置 Router
参数以根据需要编写 URL.不要编辑您的 htaccess 文件,否则它会/会破坏 CakePHP 路由.
You do this in your Config
outes.php
file. Set the Router
params to write the URL as you need. Do not edit your htaccess files or it can/will break CakePHP routing.
Router::connect('/:controller/:param1/:param2', array('action' => 'index'), array('param1' => '[a-zA-Z0-9]+', 'param2' => '[a-zA-Z0-9]+'));
这应该将所有请求发送到任何控制器到该控制器的索引函数并传递参数 1 和 2.当然,这可以高度定制.我强烈建议您阅读文档中有关路由的内容,除非必须,否则不要更改 htaccess.
This should send all requestes to any controller to the index function of that controller and pass params 1 and 2. Of course, this can be heavily customized. I would strongly suggest you read about routing in the documentation and never alter htaccess unless you have to.
http://book.cakephp.org/2.0/en/development/routing.html#routes-configuration
这篇关于从cakephp中的Url中删除动作名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!