如何使用 wamp 和 codeigniter 从 url 中删除 index.php

首先要做的是在 wamp 上启用 mod 重写到 Apache 模块并向下滚动列表

如果没有显示勾选启用它,然后重新启动所有服务器。

https://i.stack.imgur.com/go2OZ.jpg

Linux 用户也可以使用下面的 terminal 命令启用重写模块

sudo a2enmod rewrite

然后使用以下命令重启 apache

sudo service apache2 restart

然后在应用程序文件夹的外面创建一个名为 .htaccess 的文件

project > application

project > system

project > .htaccess

project > index.php

请尝试以下代码

Options +FollowSymLinks
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L]

如果不是这里是一些更多的 htaccess 示例

然后转到 config.php 文件。设置 base_url 并将 index_page 设为空白

    $config['base_url'] = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http");
    $config['base_url'] .= "://".$_SERVER['HTTP_HOST'];
    $config['base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
    $config['index_page'] = '';

希望这有助于你将示例中的 htaccess 文件用于其他人。