Welcome Guest, Not a member yet? Register   Sign In
The definitive solution for the index.php of CodeIgniter
#1

[eluser]Unknown[/eluser]
After saying a lot of people asking how to remove the index.php from the URL and a lot of people replying wrongly or with an incomplete 'solution' I'm here to help you out with this fantastic PHP MVC framework, CodeIgniter.

You probably notice that a lot of people say to put or edit the file .htaccess and then to edit the application/config/config.php and to make sure that the module called mod_rewrite is loaded. Here is the thing: a lot of people, to save time, uses the excellent tools like WAMP , LAMP or XAMPP to install all at once: Apache server, PHP and MySQL. Some people say to install each one by hand. In some distro, it is installed by default and in Windows (any) you must install it manually or use the tools that I have mentioned.

So, let's begin with some basic commands:

1) Make sure that APACHE is running with the module mod_rewrite enabled. How to check it? Open your linux/windows prompt and locate your installed apache folder, find the bin directory/folder and type: httpd -M and you will get a list of modules installed. Try to find the following: rewrite_module (shared) . If you don't find it, you should (for example) do in WAMP the following: click in the icon of WAMP then Apache -> Apache Modules -> mod_rewrite (check it and the server will be restarted). If you want to load it manually, check it out at the official site of Apache, in the configuration area, the right place to load your module. Now, you are almost ready to go.

2) Check out where you had installed your CodeIgniter framework. Some common places for your web root are: c:\wamp\www or public or htdocs folder. There you will find in the version 2.0.2 two files called: index.php and license.txt . So, you will need to create a file right there called .htaccess (linux users are familiar with .somefile_configuration) but I'm here trying to help people that uses windows or linux. So, open some smart IDE that will enable you to save a file called .htaccess and put the following lines:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php?/$1

Warning: AVOID any blank lines or spaces/tabs in this file. Some OS and Apache version will not recognize some line with tabs or some kind of identation.

Save the file.

3) Now, in CodeIgniter, find the following file: Go to your codeigniter files/folders and find the folder called application/config/config.php . Make a copy/backup of it. Edit your config.php and find the following line:

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

and replace by :

$config['index_page'] = '';

4) Now, restart your apache server manually or using your wamp/lamp/xampp and your application/site/whatever will works without the annoying index.php file, example:

before: www.someshamesitexyz.com/index.php/your_stuff

now: www.someshamesitexyz.com/your_stuff

I have done this simple and chewed instructions because I got tired and pissed off with some "smarty" guys that don't help the newbies and I have seen a lot of arrogant people trying to help with incomplete steps.

Please, let me know if my explanation helped you.

Any troubles, drop me an email: [email protected]

Regards,

Luiz Roberto Meier




Theme © iAndrew 2016 - Forum software by © MyBB