在windows中打开httpd.conf一般位于Apache安装目录
/apache/conf/httpd.conf
和
/etc/httpd/httpd.conf
在基于 Unix 的系统中。 httpd.conf 是一个 Apache 配置文件,里面存储了关于服务器的各种信息。
搜索模块mod_rewrite.so 或(mod_rewrite.c 在极少数情况下)。 mod_rewrite 模块用于动态重写请求的 URL。大多数情况下,您会发现处于注释状态。
#LoadModule rewrite_module modules/mod_rewrite.*
这里#字符代表它被评论或禁用。
LoadModule rewrite_module modules/mod_rewrite.*
删除 # 并在 windows 中使用命令 apache -k restart 或在 unix 系统中使用 service httpd restart 命令重新启动 Apache Http Server。您还可以使用 XAMPP/Wamp UI 在 Windows 系统中重新启动 Apache。
接下来在您的 CodeIgniter 项目所在的根目录中创建 .htaccess 文件并粘贴以下代码
# index file can be index.php, home.php, default.php etc.
DirectoryIndex index.php
# Rewrite engine
RewriteEngine On
# condition with escaping special chars
RewriteCond $1 !^(index\.php|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
下一步找到CodeIgniter的配置文件,一般位于其配置目录下。
./application/config/config.php
打开文件并将$config['index_page'] 值设为空。看起来像这样
/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = '';
现在故事结束了。一切都应该正常工作。您可以在 Apache Module mod_rewrite 找到有关 httpd.config 的更多信息。希望这对您有所帮助。谢谢!!