简体   繁体   English

cakePHP 2.x重定向

[英]cakePHP 2.x redirecting

First link redirects to posts, as "localhost/posts", but the other one doesn't redirect to "localhost/albus", but instead to "localhost/app/webroot/albums/" 第一个链接重定向到帖子,如“ localhost / posts”,但另一个链接不重定向到“ localhost / albus”,而是重定向到“ localhost / app / webroot / albums /”

And yes the album has it's index page 是的,专辑有索引页

The code: 编码:

<?php
    echo '<li><a href="/posts">Posts</a></li>';
?> 
<?php 
    echo '<li><a href="/albums">albums</a></li>';
?> 

Check if there are any redirects that are not done by the CakePHP application, ie in your .htaccess files. 检查是否有CakePHP应用程序未完成的任何重定向,即在您的.htaccess文件中。

Try if specifying a RewriteBase in the .htaccess works. 尝试在.htaccess指定RewriteBase是否有效。

/.htaccess /.htaccess

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

/app/webroot/.htaccess /app/webroot/.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /app/webroot/
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

Instead of using plain HTMLyou can use Cakephp syntax which will help you to redirect on which action you have to redirect. 您可以使用Cakephp语法来代替普通的HTML,它可以帮助您重定向必须重定向的操作。

According to your code that should work but you have to define some rules in you virtual host. 根据应该工作的代码,但是您必须在虚拟主机中定义一些规则。 Simple solution use cake php syntax, 简单的解决方案使用cake php语法,

For example : 例如 :

<?php echo $this->Html->link(__('Album List'), array(
 'controller' => 'alubms', 
 'action' => 'index'),
 array('title'=>'<title>','class' => <class_if_any>));
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM