[英]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到这样的网址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). $route 数组的键是指向控制器功能的实际 url(没有基本 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().我假设您在主控制器中的函数称为 about()。
You find more information here: URI Routing您可以在此处找到更多信息: URI 路由
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.