Codeigniter | Remove index.php from site_url or anchor functions

I need to remove index.php from site_url() return value I don't want search engines cache my URLs contain index.php.

I removed index.php from url by setting .htaccess file but still not working.

For example, when I use site_url() in part of my project, search engines cache the URL like http://url/index.php/controller. I remove index.php from site_url function in system/helper but I think the redirect and form_open functions don't work properly.


write in your .htaccess file

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

And set index_page config in config.php

$config['index_page'] = '';

You can use base_url() function:

echo base_url(); // http://example.com/website
echo site_url(); // http://example.com/website/index.php