Reputation: 442
I have deployed a website that uses CodeIgniter in the main public_html folder (http://www.myexample.com)
. This project working perfectly on localhost. In order to remove index.php from URL this has the following .htaccess:
RewriteEngine on
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1
However, when I try to go to the website I'm getting an Internal Server Error:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at [email protected] 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.
I have applied differently .htaccess files but getting the same error.
Upvotes: 4
Views: 10258
Reputation: 387
I just figured out that after verifying DB credentials correctly, the .htaccess file is mostly the one causing trouble. I deleted what i had on cpanel and uploaded another Boom It worked!
Just for future users
Upvotes: 0
Reputation: 7
If you are on Ubuntu 16.04, 18.04 or 20.04 try this-
sudo a2enmod rewrite
and restart your apache server
systemctl restart apache2
I hope it will solve your issue, it works for me.
Upvotes: 1
Reputation: 11
I had the same problem but I figured it out.
Make sure all your database configuration are collect. Here you may try in your index.php (root);
if( mysqli_connect('hostname', 'username', 'password', 'database')) { echo 'ok'; }
if OK then go to your .htaccess file.
In your .htaccess file, Leave this line blank
RewriteBase /
Upvotes: 1
Reputation: 2971
What I usually do when migrating to live server are as follows
first .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>
then database username and password
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
);
Then in config file
application / config / config.php
$config['base_url'] = 'http://example.com/';
if still you are getting error saying cannot connect, try verifying the database username, name and password and try changing the database password just to make sure its correct
UPDATE
Check the file permission and make sure it is 644
and folder permission to 755
Also check php
, mysql
versions and make sure php
version is atlease 5.6
or higher and check server requirements of your framework.
Upvotes: 7
Reputation: 63
Try this, its working for me.
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]
Upvotes: 3