1、修改 apache 配置文件conf/httpd.conf 或者 httpd-vhost.conf
<VirtualHost *:80>
ServerAdmin eric_zhang@youkuaiyun.com
DocumentRoot "D:/htdocs/ci/"
ServerName www.ci.com
<Directory "D:/htdocs/ci/">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
- 开启重写模块 LoadModule rewrite_module modules/mod_rewrite.so
- AllowOverride None 修改为 AllowOverride All
2、在CI根目录添加 .htaccess 文件
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
#如果没有安装mod_rewrite模块,所有的404页面都将被 #发送到index.php,此时,程序会像没有设置隐藏时一样运行
ErrorDocument 404 index.php
注意:若不在网站根目录,index前面记得带上相应的目录
3、修改ci中 config.php 文件
$config['index_page'] = "index.php";
修改为
$config['index_page'] = "";
❄❄❄ 注意:配置完成以后,记得重启服务器,设置才能生效。 ❄❄❄
本文介绍如何通过Apache配置实现CodeIgniter框架的URL重写功能,包括修改Apache配置文件启用重写模块、添加.htaccess文件配置及调整CodeIgniter配置文件等内容。
3750

被折叠的 条评论
为什么被折叠?



