欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程语言 > php >内容正文

php

ci框架去除index.php,ci框架如何隐藏index.php

发布时间:2025/3/21 php 31 豆豆
生活随笔 收集整理的这篇文章主要介绍了 ci框架去除index.php,ci框架如何隐藏index.php 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

1. 修改 apache 配置文件

开启重写模块 conf/httpd.conf

去掉前面的#

LoadModule rewrite_module modules/mod_rewrite.so

对于Ubuntu,需要在apache安装目录下的 mods-enabled 文件夹中创建软连接。

进入 /mods-enabled 下,

-s ../mods-available/rewrite.load rewrite.load # 要确保 ../mods-available/rewrite.load 文件存在,不存在需要安装rewrite模块

注:apache安装目录下:mods-available---未启用的模块,mods-enabled----已启用的模块

AllowOverride None 修改为 AllowOverride All

可以在apache的配置文件 conf/httpd.conf 末尾添加如下代码,或是在 sites-enabled 文件夹下新建个 .conf 文件,文件名随意,也可像 mods-enabled/ 下那样创建链接。

Alias /athena "/home/liuqian/workspace/athena/" # 依据实际情况改为自己的路径 # 依据实际情况改为自己的路径

Options Indexes MultiViews FollowSymLinks AllowOverride All # 主要是这个

Order allow,deny

Allow from all

注:apache安装目录下:sites-available---未加载的配置文件,sites-enabled----已加载的配置文件

2. 添加 .htaccess 文件

进入到项目文件夹下,在 index.php 所在的目录下创建 .htaccess 文件

文件中写如下:

/%{REQUEST_FILENAME} !-%{REQUEST_FILENAME} !- !^(index\.php| index.php

3. 修改Ci配置文件 application/config/config.php

$config['index_page'] = "index.php";

改为:

$config['index_page'] = "";

4. 重启apache 就ok了。

sudo apachectl restart # 这里是ubuntu的重启命令

总结

以上是生活随笔为你收集整理的ci框架去除index.php,ci框架如何隐藏index.php的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。