实时主机上的 codeigniter 内部服务器错误

Internal Server Error in codeigniter on live host

我在 public_html 主文件夹 (http://www.myexample.com) 中部署了一个使用 CodeIgniter 的网站。该项目在本地主机上完美运行。为了从 URL 中删除 index.php 这具有以下 .htaccess:

RewriteEngine on
RewriteCond  !^(index\.php|public|\.txt) 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?

但是,当我尝试访问网站时出现内部服务器错误:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at webmaster@its.org.pk to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

我应用了不同的 .htaccess 文件,但出现了同样的错误。

试试这个,它对我有用。

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

我在迁移到live server时通常做的事情如下
第一.htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/ [L]

#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/ [L]

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/ [L]
</IfModule>

然后数据库用户名和密码
application / config / database.php

$db['default'] = array(
'dsn'   => '',
'hostname' => 'localhost',
'username' => 'DATABASE_USERNAME',//database username here
'password' => 'DATABASE_PASSWORD',//database password here
'database' => 'DATABASE_NAME',//database name here
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);

然后在配置文件中 application / config / config.php

$config['base_url'] = 'http://example.com/';

如果仍然出现无法连接的错误,请尝试验证数据库用户名、名称和密码,并尝试更改数据库密码以确保其正确

更新
检查文件权限并确保它是 644 和文件夹权限 755
还要检查 phpmysql 版本并确保 php 版本至少为 5.6 或更高版本并检查框架的服务器要求。

我遇到了同样的问题,但我想通了。

  1. 确保收集所有数据库配置。 在这里你可以试试你的 index.php (root);

    if( mysqli_connect('hostname', 'username', 'password', 'database')) { 回声'ok'; }

    如果确定,则转到您的 .htaccess 文件。

  2. 在您的 .htaccess 文件中,将此行留空

    RewriteBase /

如果您使用的是 Ubuntu 16.04、18.04 或 20.04,试试这个-

sudo a2enmod rewrite 并重启你的apache服务器 systemctl restart apache2

我希望它能解决你的问题,它对我有用。

2021 年 6 月更新

我刚刚发现,在正确验证数据库凭据后,.htaccess 文件主要是导致问题的原因。我删除了我在 cpanel 上的内容并上传了另一个 Boom 它成功了!

仅供未来用户使用