简体   繁体   中英

How to URL rewrite in CodeIgniter?

My routes configuration only contains following route:

$route['default_controller'] = "frontend/home";

I would like to rewrite the default route

http://192.168.1.4/sncraft/frontend/home/about

to an url like this http://192.168.1.4/sncraft/about

The content of the controller is:

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

class Home extends CI_Controller {

    public function __Construct(){
        parent::__Construct();

        $this->load->library('image_lib');
        $this->load->model('frontend/front_model');
    }


    public function index(){
        $config = array();
        $config["base_url"] = base_url()."frontend/home";
        $this->viewForm();
    }   

    public function about(){
        $this->load->view('frontend/header');
        $this->load->view('frontend/about');
        $this->load->view('frontend/footer');
    }   
}

?>

The key of the $route array is the actual url which leads to the function of the controller (without the base url).

Your route would look like this:

$route['about'] = "frontend/home/about";

I'm assume that your function inside the home-controller is called about().

You find more information here: URI Routing

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