如果在codeigniter中删除了如何修复URL?

时间:2017-11-22 08:08:43

标签: php html codeigniter

我的网址http://localhost/ci_sai/home/detail/berhalusinasi-adik-bunuh-kakak-sepupu

如果此链接已删除为http://localhost/ci_sai/home/detail/berhalusinasi-adik-bunuh

,如何重定向到ERROR 404

我正在使用codeigniter

1 个答案:

答案 0 :(得分:0)

试试这个(例子):

public function detail($slug='')
{
    $page = $this->db->get_where('pages',['slug'=>$slug])->row();
    if(!$page) {
        show_404();
        return;
    }       
    [...]
}

OR

public function detail($slug='')
{
    $page = $this->db->get_where('pages',['slug'=>$slug])->row();
    if(!$page) redirect('home/detail/berhalusinasi-adik-bunuh');    
    [...]
}