To remove index.php from URL using .htaccess file in CodeIgniter. htaccess is the shortened used for Hypertext Access, which is a powerful configuration file that controls the directory “.htaccess”. CodeIgniter’s URLs are designed to be search engine friendly and to human too. and so to maintain the standards we need to remove the default index.php which appears in the url of codeigniter applications, so that the url becomes search engine friendly and looks clean.
By default, the index.php file will be included in your URLs:
example.com/index.php/news/article/my_article
If your Apache server has mod_rewrite enabled, you can easily remove this file by using a .htaccess file with some simple rules.
Step 1:- config.php
Open config.php and do following replaces
$config['index_page'] = "index.php"
to
$config['index_page'] = ""
Step 2:- config.php
In some cases the default setting for uri_protocol
does not work properly. Just replace
$config['uri_protocol'] ="AUTO"
by
$config['uri_protocol'] = "REQUEST_URI"
Step 3:- .htaccess
RewriteEngine on RewriteCond $1 !^(index\.php|resources|robots\.txt) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Note: .htaccess code vary depending on hosting server. In some hosting server (e.g.: Godaddy) need to use an extra ? in the last line of above code. The following line will be replaced with last line in applicable case:
// Replace last .htaccess line with this line RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
Contact Controller [crayon-67a5aeb115926912111924/] Contact_form.php - view [crayon-67a5aeb115930175166200/] Contact_model [crayon-67a5aeb115934545074500/] Captcha Helper [crayon-67a5aeb11593b836133567/] Notifications_model [crayon-67a5aeb115943143749098/] Database…
[crayon-67a5aeb115cbf289298729/] [crayon-67a5aeb115cc4633363276/]
[crayon-67a5aeb115dda565363527/] The first parameter specifies the type of string, the second parameter specifies the length.…
Create Controller [crayon-67a5aeb115f1c654432805/] 2. Create View File [crayon-67a5aeb115f20754258738/]
[crayon-67a5aeb115fee281901142/] [crayon-67a5aeb115ff0818664986/]
All of the native error messages are located in the following language file: system/language/english/form_validation_lang.php To set…