000webhost 和 codeigniter

000webhost and codeigniter

我正在尝试在 000webhost 的共享服务器中使用 codeigniter。我上传了包的内容,如果我输入

http://groceriesapi.000webhostapp.com/API/index.php/welcome/

确实有效。但如果我访问:

http://groceriesapi.000webhostapp.com/API/welcome/

你得到一个 404。

我在网上看到应该用 .htaccess 文件解决这个问题。首先,我的文件夹结构中有两个。这是它的样子:

public_htm
    application
       plenty of things
       .htaccess
    other stuff
    .htaccess

我将 public_html 处的外部 .htacces 编辑为如下所示:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/ [L]

现在访问简化的 URL (http://groceriesapi.000webhostapp.com/API/welcome/) 时出现 500 内部服务器错误!

有线索吗???

PS:我不会关心 URL 中间的 index.php,但是每当我收到错误消息时,整个 codeigniter 就会崩溃,我不知道出了什么问题..那是个问题:(

步骤:-1打开文件夹“application/config”并打开文件“config.php”。在 config.php 文件中找到并替换以下代码。

//find the below code   
$config['index_page'] = "index.php" 
//replace with the below code
$config['index_page'] = ""

步骤:-2 转到您的 CodeIgniter 文件夹并创建 .htaccess

Path:
Your_website_folder/
application/
assets/
system/
.htaccess <——— this file
index.php

步骤:-3在.htaccess文件中写入以下代码

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/ [L] 
</IfModule>

步骤:-4 在某些情况下,uri_protocol 的默认设置无法正常工作。要解决这个问题,只需打开文件“application/config/config.php”,然后找到并替换下面的代码

//find the below code
$config['uri_protocol'] = "AUTO"
//replace with the below code
$config['uri_protocol'] = "REQUEST_URI" 

这就是全部,但在 wamp 服务器中它不起作用,因为 rewrite_module 默认情况下禁用,因此我们需要启用它。为此,请执行以下操作

  1. 左键单击 WAMP 图标
  2. 阿帕奇
  3. Apache 模块
  4. 左键单击rewrite_module

Original Documentation

Example Link

PS:这个答案是从 CodeIgniter removing index.php from url 逐字复制的。只发在这里是因为这个问题必须作为赏金的一部分得到回答