Codeigniter Initial Settings

Eliminating index.php in codeigniter is not difficult, but if you forget or don’t know how, the website may not run properly.

htaccess

This afternoon, a friend asked about his website, after uploading it to hosting, how come it didn’t work well, the CSS wasn’t found.

This can all be caused by incorrect htaccess or incorrect config settings.

The following is the initial codeigniter setting that can be used. (Not only to remove index.php) but for initial settings when you use codeigniter as a website framework.

config.php
First try to open the config.php file located in application/config
Base_url should be left blank if you are using Codeigniter 2.XX
$config[‘base_url’] = “”;

index_page should also be left blank, for better seo, but also need htaccess to complete this setting.
$config[‘index_page’] = ”;

Uri_protocol is made AUTO
$config[‘uri_protocol’] = ‘AUTO’;

Encryption_key should be filled with random characters.
$config[‘encryption_key’] = ‘B3b4SSsss555’;

sess_cookie_name should be changed, so that the ROBOT created by irresponsible people cannot detect if your website was created with codeigniter.
$config[‘sess_cookie_name’] = ‘whatever’;

sess_encrypt_cookie should be set TRUE so that cookies are encrypted
$config[‘sess_encrypt_cookie’] = TRUE;

Other settings related to sessions and cookies should also be changed to be more secure 🙂

HTACCESS
To complete the codeigniter website settings so that it runs properly, and so that the index.php in the URL is also lost, it is necessary to create a file without a name but with the extension .htaccess


Options -Indexes

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} ^system.*

RewriteRule ^(.*)$ /index.php/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index.php|images|robots.txt)
RewriteRule ^(.*)$ /folder_name/index.php?/$1 [L]


# If we don’t have mod_rewrite installed, all 404’s
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin

ErrorDocument 404 /folder_name/index.php


there it says folder_name, because it was created in a folder in htdocs, when uploaded to the hosting server, usually we don’t put it in the folder, but directly in the public_html, so when hosted /folder_name must be deleted, leaving only /index.php.