If we need a clean url in codeigniter. we need to remove index.php from url in codeigniter. Default you will get index.php in url in codeigniter cause index.php file included with url in codeigniter. so url looks like :

codeigniter provide easy way for url rewrite functionality to get clean url or remove index.php from url in codeigniter. we can easily done by using .htaccess some of config file changes. after remove index.php from url you will see controller name in url like “http://example.com/controller”.
We need to remove index.php from url so we can get clean url for our codeigniter site and url not looks odd or to get a user friendly or seo friendly url.

Steps to remove index.php from url codeigniter :-

Config changes :- Go to “application/config/config.php”

Find below code:-

1$config['index_page'] = 'index.php';

Replace with the below code:-

1$config['index_page'] = '';

.htaccess changes :- If you not have any htaccess create new and place it on your root.

Note :- if you have codeigniter in subdirectory change RewriteBase / to RewriteBase /subdir/

123456RewriteEngine onRewriteBase /RewriteCond $1!^(index.php|resources|robots.txt)RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule ^(.*)$ index.php/$1[L,QSA]

Now open your site pages you will found clean url with no index.php. so your all url looks like http://example.com/controller/method. Now any of HTTP request for index.php will be treated as a request for your index.php file.

If still issue:- Need to apply one more config changes.
Go to “application/config/config.php”
Find below code

1$config['uri_protocol'] = 'AUTO';

Replace with the below code

1$config['uri_protocol'] = 'REQUEST_URI';

Now you have fully done to remove index.php from url codeigniter and getting clean url in codeigniter.