活动主机上的codeigniter中的内部服务器错误

时间:2017-07-16 06:35:35

标签: php .htaccess codeigniter internal-server-error

我在主public_html文件夹(http://www.myexample.com)中部署了一个使用CodeIgniter的网站。这个项目完全适用于localhost。为了从URL中删除index.php,它具有以下.htaccess:

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

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

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文件,但收到了相同的错误。

5 个答案:

答案 0 :(得分:4)

迁移到实时服务器时我通常做的事情如下
第一个.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?/$1 [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?/$1 [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?/$1 [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/';

如果您仍然收到错误提示无法连接,请尝试验证数据库用户名,名称和密码并尝试更改数据库密码以确保其正确无误

更新
检查文件权限并确保644755的文件夹权限
另请检查phpmysql版本并确保php版本已发布5.6或更高版本,并检查框架的服务器要求。

答案 1 :(得分:3)

试试这个,它为我工作。

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

答案 2 :(得分:0)

我有同样的问题,但我想出来了。

  1. 确保收集所有数据库配置。 在这里,您可以尝试使用index.php(root);

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

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

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

    RewriteBase /

答案 3 :(得分:0)

如果您使用的是Ubuntu 16.04、18.04或20.04,请尝试以下操作-

dt[, year := ifelse(stringr::str_detect(year_week, "^y_90"), "1990", ifelse(str_detect(year_week, "^y_91"), "1991", NA ))] 并重新启动apache服务器 sudo a2enmod rewrite

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

答案 4 :(得分:0)

2021 年 6 月更新

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

仅供未来用户使用