始终使用URL Rewrite和Codeigniter重定向到404页面

时间:2012-01-10 22:37:43

标签: php .htaccess codeigniter

所以我下载了一份干净的Codeigniter副本,并用(分别)代替欢迎控制器和welcome_message视图:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends CI_Controller
{
    public function index()
    {
        $this->load->view('welcome_message');
    }

    public function test($number = 3)
    {
        echo $number;
    }
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

<!DOCTYPE HTML>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <div>
            <a href="<?php echo base_url(); ?>pouet/lolmdr-2.html">LOLMDR</a>
        </div>
    </body>
</html>

和我的.htaccess文件是:

RewriteEngine on

RewriteRule ^pouet/(.*)-([0-9]+)\.html$ index.php/welcome/test/$2

我认为当我点击链接时,我会被重定向到我的欢迎/测试功能,然后回显2.但我有一个404页面,我不明白为什么。

由于

1 个答案:

答案 0 :(得分:1)

将此添加到路线

$route['test/(:num)'] = 'welcome/test/$1';

然后转到网址:

http://www.yoursite.com/test/3457

让我们知道结果老兄

welcome是您的默认控制器,因此:

http://www.yoursite.com , will always = http://www.yoursite.com/welcome