This tutorial shows how to remove index.php from URL in Codeigniter. We want to remove the index.php file so that URL looks good and it makes better readability. Also the clean URL is easy to remember.
Before you change anything in comfig.php and .htaccess file make sure you have mod_write enabled in the server ottherwise it won’t work. For localhost you can enable it yourself and for live server if it does not work then you can contact with the hosting company.
<root directory> – is the root directory under htdocs in localhost or public_html(live server)
Check below things in <root directory>/application/config/config.php file
config.php
$config['base_url'] = ''; $config['index_page'] = ''; $config['uri_protocol'] = 'AUTO'; $config['url_suffix'] = '';
Put the below lines in .htaccess file which is under <root directory>
.httacces
#Initialize mod_rewrite RewriteEngine On # Put your installation directory here: # If your URL is www.example.com/, use / # If your URL is www.example.com/site_folder/, use /site_folder/ RewriteBase /<root directory>/ # Do not enable rewriting for files or directories that exist RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d #For reuests that are not actual files or directories, #Rewrite to index.php/URL RewriteCond $1 !^(index\.php|resources|robots\.txt) RewriteRule ^(.*)$ index.php/$1 [L,QSA] RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC] RewriteRule ^ /%1 [R=301,L]
That’s all. Thanks for your reading. Please do not forget to leave a comment.
Tags: codeigniter clean URL • htaccess • mod_rewrite • remove index.php from url
Very nice article, totally what I was looking for.
I needed to thank you for this great read!! I certainly loved every bit
of it. I have you bookmarked to look at new stuff you post…