php - 从 CodeIgniter URL 中删除 index.php

标签 php apache .htaccess codeigniter mod-rewrite

我正在努力删除 CodeIgniter URL 中的“index.php”部分。 我正在使用 CodeIgniter 版本 3.1.2。我已按照有关此问题的其他问题执行所有步骤:

  • $config['index_page'] = 'index.php' 更改为 $config['index_page'] = ''
  • $config['uri_protocol'] = 'AUTO' 更改为 $config['uri_protocol'] = 'REQUEST_URI'
  • 在我的项目的根文件夹中添加了一个 .htaccess 文件,其中包含以下代码:

RewriteEngine 开启 RewriteCond $1 !^(index\.php|resources|robots\.txt) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L,QSA]

但是,当我尝试访问我的网站时,收到以下错误代码。

Not Found

The requested URL /Toneel/Site/index was not found on this server.

我的 Apache 服务器中的重写模块已打开。 谁能帮我解决这个问题吗?

最佳答案

这个设置对我有用。

$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

.htaccess

<IfModule mod_rewrite.c>
  RewriteEngine On
  #RewriteBase /

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^ index.php [QSA,L]
</IfModule>

要允许在 Apache 配置中覆盖 htaccess,您必须编辑 /apache2.conf 文件并将其更改为

AllowOverride All

并重新启动服务器。

关于php - 从 CodeIgniter URL 中删除 index.php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42455371/

相关文章:

PHP 购物车 - 添加变量

php - 在安装了 Twig 的 PHPUnit 中进行单元测试

php - 如何在导航栏 CSS 和 HTML 上方显示图像

python - 如何刷新 PCF 上托管的 python CGI 文件中的 STDOUT?

php - Laravel 403 禁止错误

php - 多行查询时 PDO 获取失败

php - 更新 Ubuntu 服务器错误后与 apache 一致

java - 如何将 Apache Archiva 设置为所有 Maven 项目的缓存?

apache - .htaccess:提供静态文件,将其他所有内容路由到 index.php

.htaccess - 我想在 .htaccess 中允许 IP 范围