PHP框架CodeIgniter--URL去除index.php

今天学习CodeIgniter简称CI的第一天,记录下学习心得。php

CI中国https://codeigniter.org.cn/user_guide/general/urls.html?highlight=url 这里有介绍html

example.com/class/function/ID 
  1. 第一段表示要调用的控制器 类 ;
  2. 第二段表示要调用的类中的 函数 或 方法 ;
  3. 第三段以及后面的段表明传给控制器的参数,如 ID 或其余任何变量;

移除 URL 中的 index.php

默认状况,你的 URL 中会包含 index.php 文件:apache

example.com/class/function/ID

一、

若是你的 Apache 服务器启用了 mod_rewrite ,你能够简单的经过一个 .htaccess 文件(放在index.php同级目录)服务器

再加上一些简单的规则就能够移除 index.php 了。下面是这个文件的一个例子, 其中使用了 "否认条件" 来排除某些不须要重定向的项目:app

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

在上面的例子中,除已存在的目录和文件,其余的 HTTP 请求都会通过你的 index.php 文件。ide

或者不使用.htaccess 直接在apache配置文件中函数

<Directory />
Require all granted
AllowOverride all
Order allow,deny
Allow from all
</Directory>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.*)$ /index.php?/$1 [L]
</IfModule>codeigniter

二、学习

 httpd.conf 开启 LoadModule rewrite_module modules/mod_ rewrite.so 
若是已开启,能够忽略。
三、重启apache
 
四、application/config.php 中的 $config['index_page'] = 'index.php';  --》index.php$config['index_page'] = '';
 
http://192.168.1.89/welcome/index
相关文章
相关标签/搜索