【问题标题】:CodeIgniter 500 Internal Server Error 7CodeIgniter 500 内部服务器错误 7
【发布时间】:2016-09-08 11:56:07
【问题描述】:

这实际上是我第一次将 CodeIgniter 项目上传到 Web 服务器。我无法访问其他页面,但默认控制器的 index() 可以正常工作。

我在互联网上搜索过相同的情况,但找不到任何解决方案。

这是 .htaccess 文件

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /schoolportal
  RewriteCond %{REQUEST_URI} ^system.*
  RewriteRule ^(.*)$ /index.php/$1 [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond $1 !^(index\.php|images|robots\.txt|css)
  RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
  ErrorDocument 404 /index.php
</IfModule>

当我尝试删除 RewriteBase 或将其更改为仅“/”时,我收到 404 Not Found 错误。

这里是配置文件:

$config['base_url'] = 'http://sctportal.org/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

还有路由文件:

$route['default_controller'] = 'SchoolPortal';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;

【问题讨论】:

  • 首先您需要确保启用了重写模块?
  • 如何知道它是否启用?
  • 使用 phpinfo();函数和搜索重写
  • 我在那里看不到任何关于 mod rewrite 的信息。确切的选项名称是什么?
  • 尝试将此行更改为RewriteRule ^(.*)$ index.php?/$1 [L]。注意额外的问号。

标签: php .htaccess codeigniter


【解决方案1】:

在 config.php 中做一些调整:

$config['uri_protocol'] = "REQUEST_URI";

如果您使用 Linux 服务器,还有一件事,因此必须进行这些更改。

1) 您的班级名称应以大写字母开头,即 cat 应为 Cat

2) 使用大写字母保存控制器类,即cat.php 应为Cat.php

【讨论】:

  • 还提到版本
  • 你把它上传到主目录或子目录还有一件事是这个服务器是Linux?
  • htaccess文件在主目录
【解决方案2】:

能否请您将 .htaccess 更新到以下内容

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

请检查配置文件中的 base_url 为

$root  = "http://".$_SERVER['HTTP_HOST'];
$root .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
$config['base_url']    = "$root";

/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = 'index.php';

中删除index.php
$config['index_page'] = 'index.php';

如果你不想在你的 url 中使用 index.php

【讨论】:

  • 你能用配置文件和路由文件更新你的吗?所以我们来看看。
  • 如果你用我给定的代码替换 htaccess 并用我给定的代码更新 base_url 它应该可以工作。那么,当您提到 index() 完美运行时,我们能否获得显示错误的 url
  • 它仍然给我找不到 404 页面
猜你喜欢
  • 1970-01-01
  • 2013-12-03
  • 2018-02-22
  • 2012-05-01
  • 1970-01-01
  • 2014-08-21
  • 2011-10-04
  • 1970-01-01
  • 2018-04-09
相关资源
最近更新 更多