linux下ci(CodeIgniter)框架美化url,实现伪静态重写url的方法

开启apache伪静态

打开配置文件httpd.conf:

1、启用rewrite

LoadModule rewrite_module modules/mod_rewrite.so 去除前面的 #

2、启用.htaccess
在虚拟机配置项中

AllowOverride None 修改为: AllowOverride All

3、重启apache

service httpd restart

/usr/local/apache2/bin/apachectl restart

配置ci框架根目录下.htaccess文件

编辑 vim .htaccess,内容如下:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)/(.*)$ index.php?c=$1&m=$2 [L]

配置控制器controller

控制器Welcome.php 代码如下

扫描二维码关注公众号,回复: 5694277 查看本文章
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Welcome extends CI_Controller {

	public function index()
	{
		$this->load->view('welcome_message');
	}
	
	public function hi()
	{
		$this->load->view('hi_message');
	}
}

视图层views 目录下hi_message.php代码如下:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?><!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>HI to CodeIgniter</title>

	 
</head>
<body>

<div id="container">
	<h1>HI to CodeIgniter!</h1>

</div>

</body>
</html>

浏览器中访问

http://yiyi.ci.com/welcome/hi
http://yiyi.ci.com/控制其名称/方法
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/guo_qiangqiang/article/details/88869760