route - cakephp controller URL修改

WBOY
Release: 2016-06-06 20:32:27
Original
1126 people have browsed it

最近在用cakephp开发小项目。发现一个问题,网上搜材料暂时没有找到解决方案,想要请教一下各位大牛。

cakephp 放在网站根目录下的/animal/文件夹中,所有URL都是
http://sample.com/animal/:controller/...

想要将其中一个controller的内容拿到上一级目录,例如将名为dog的controller改变成
http://sample.com/animal/dog/...
http://sample.com/dog/...

目前做法是修改根目录下的.htaccess 文件

<code>Options +FollowSymLinks
RewriteEngine on

RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !\.[^/\.]+$
RewriteRule .* %{REQUEST_URI}/ [L,R]

RewriteRule ^dog/(.*)/ animal/dog [L]
RewriteRule ^dog/(.*) animal/dog [L]
</code>
Copy after login
Copy after login

但是有一个问题,view中HtmlHelper中的链接仍然有/animal/,
Paginator也自动加有/animal/

<code>echo $this->Html->link(
    'Dog',
    array('controller' => 'dog', 'action' => 'smile')
);
URL: http://sample.com/animal/dog/smile
</code>
Copy after login
Copy after login

如何在cakephp配置中修改此类问题?同时不影响其他controller的链接呢?

感谢感谢!!

回复内容:

最近在用cakephp开发小项目。发现一个问题,网上搜材料暂时没有找到解决方案,想要请教一下各位大牛。

cakephp 放在网站根目录下的/animal/文件夹中,所有URL都是
http://sample.com/animal/:controller/...

想要将其中一个controller的内容拿到上一级目录,例如将名为dog的controller改变成
http://sample.com/animal/dog/...
http://sample.com/dog/...

目前做法是修改根目录下的.htaccess 文件

<code>Options +FollowSymLinks
RewriteEngine on

RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !\.[^/\.]+$
RewriteRule .* %{REQUEST_URI}/ [L,R]

RewriteRule ^dog/(.*)/ animal/dog [L]
RewriteRule ^dog/(.*) animal/dog [L]
</code>
Copy after login
Copy after login

但是有一个问题,view中HtmlHelper中的链接仍然有/animal/,
Paginator也自动加有/animal/

<code>echo $this->Html->link(
    'Dog',
    array('controller' => 'dog', 'action' => 'smile')
);
URL: http://sample.com/animal/dog/smile
</code>
Copy after login
Copy after login

如何在cakephp配置中修改此类问题?同时不影响其他controller的链接呢?

感谢感谢!!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template