【问题标题】:Remove index.php from codeigniter project on localhost and apache server从 localhost 和 apache 服务器上的 codeigniter 项目中删除 index.php
【发布时间】:2021-10-05 18:02:10
【问题描述】:

我在 CodeIgniter 中有一个项目,我在 LocalHost 上的本地计算机上运行。我必须使用 http://localhost/projectname/index.php/controller/function 来运行我的 API。我想访问相同的 URL,但在 URL 中不包含 index.php

之前我安装了 XAMPP,我使用的是它的 htdocs 文件夹,一切都按要求运行。但是现在我已经卸载了,手动设置了Apache 2.4、PHP 8、MySQL 8,这样做之后就出现了这个问题。

我是手动设置服务器和 CodeIgniter 的新手。请帮我解决这个问题,如果可能的话,请给出发生这种情况的原因,这将有助于我学习。

【问题讨论】:

  • 这能回答你的问题吗? How to remove "index.php" in codeigniter's path
  • @brombeer 我已经尝试过这个解决方案,但它不起作用
  • 您的 Apache 中是否安装并启用了 mod_rewrite.htaccess 是否允许?
  • @brombeer 我对此一无所知。也许这就是问题所在。怎么做?
  • 你已经搜索过这个网站了吗?很确定有关于这个话题的答案

标签: php apache codeigniter xampp


【解决方案1】:

在根目录下添加一个.htaccess,然后在.htaccess文件中添加如下规则

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA] 
</IfModule>

然后在您的应用程序中找到以下文件。文件路径为 application/config/config.php。在这个文件中找到下面的代码

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

如下更改该行。

$config['index_page'] = '';

现在尝试打开没有 index.php 的 URL。

【讨论】:

    猜你喜欢
    • 2015-03-11
    • 2014-11-25
    • 1970-01-01
    • 2016-05-13
    • 2018-01-27
    • 2019-03-02
    • 2014-01-07
    • 2013-09-04
    • 1970-01-01
    相关资源
    最近更新 更多