简体   繁体   中英

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/"

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.

Try if specifying a RewriteBase in the .htaccess works.

/.htaccess

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

/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.

According to your code that should work but you have to define some rules in you virtual host. Simple solution use cake php syntax,

For example :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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