【问题标题】:000webhost and codeigniter000webhost 和 codeigniter
【发布时间】:2019-07-19 14:15:32
【问题描述】:

我试图在 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

我编辑了外部 .htacces,即 public_html 中的那个:

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

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

有什么线索吗???

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

【问题讨论】:

  • 您正在寻找的可能是这个? stackoverflow.com/a/28828919/2830850
  • Dude.. 我在 SO 的每篇文章中都尝试了 200 次,但没有成功。但你的确实有效。唯一的区别..我没有重新启动apache,因为它是一个共享服务器。我该如何解决这个问题?或者我应该关闭它还是.. 什么?
  • 我将发布一个带有该线程的答案作为参考,您可以接受它作为答案
  • 完成,已发布答案。

标签: codeigniter-3 web-hosting


【解决方案1】:

步骤:-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/$1 [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逐字复制的。仅在此处发布,因为该问题必须作为赏金的一部分来回答

【讨论】:

  • 只需添加我在共享服务器中使用它,所以我没有重新启动 Apache,仍然像魅力一样工作
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-08
  • 2016-10-27
  • 1970-01-01
  • 2014-02-16
  • 2020-11-18
相关资源
最近更新 更多