In the previous tutorial, you learnt about the purpose of each and every folder in the “/application/” folder of your web applicaiton.
This is a short tutorial in which you will learn how to get rid of the “index.php” from the URL of your web application using a .htaccess file.
Problem
In a default installation of CodeIgniter 3, the URL looks like this
http://localhost/tutorial/index.php/1_hello_world/helloworld/requestModal
The URL looks bad because of the “index.php”. It is possible to get rid of “index.php” using a simple file in your application’s root.
Solution
The “index.php” can be removed by simply putting a .htaccess file in the root of your web application. Download the file from GitHub
[button link=”https://github.com/codeonion/CodeIgniter-removing-index.php” type=”big” newwindow=”yes”] DOWNLOAD from Github[/button]
The .htaccess file should contain the following text. The link I have provided from my github repository is ready for you to use.
RewriteEngine On RewriteCond $1 !^(index\.php|resources|robots\.txt) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Now go to the root folder of your CodeIgniter web application and make sure that you put the .htaccess file there.
Now, you can safely change your URLs from
<form method=”post” action=”<?php echo base_url();?>
index.php/1_hello_world/helloworld/”>To
<form method=”post” action=”<?php echo base_url();?>1_hello_world/helloworld/”>
Note that it is still possible to keep using the “index.php” in your URLs and it will show up in URL if you do.
That’s it! You have successfully removed the “need” to have “index.php” in your URLs.
If you found my post helpful or have any questions, please leave a comment.
2 responses to “CodeIgniter 3.0.1 Tutorial 3 – Getting Rid of “index.php” from URL (with download)”
still issue is not solved
Thanks for the comment. What seems to be the issue?