Reputation: 1
How to remove index.php in Codeigniter url?
http://localhost/Sample/index.php
to just
http://localhost/Sample
I've been searching whole day in the internet and nothing works. I'm using Apache2.2 and the mod_rewrite in httpd.conf have already been enabled. The version i'm using is Codeigniter 2.1.4.
Please teach my step by step. I'm still very new in Codeigniter Framework. Thanks !
Upvotes: 0
Views: 180
Reputation: 29
First Enable "mod_rewrite" in Apache server. Restart your Apache server.
Add this code to .htaccess (Folder structure is Project_Name/.htaccess)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Upvotes: 0
Reputation: 770
You just need to create .htaccess file in project folder and write:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
#And You don't need to define in base_url in config file:
$config['base_url'] = '';// blank it.
I hope it will work perfectly ...
Upvotes: 0
Reputation: 157
Try this on your .htaccess file found in the root folder:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
Upvotes: 0
Reputation: 20475
There are two places that you must make this change, one is in your /application/config/config.php
:
/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = '';
Remove the index.php
from index page.
The 2nd place is (as mentioned) in updating/creating your .htaccess
file, that sits in the same root folder as your primary index.php
file.
Referer to the CI guide: http://ellislab.com/codeigniter/user-guide/general/urls.html
It's all in the guide...
Upvotes: 1
Reputation: 3622
You can use the below code in your .htaccess file :
RewriteEngine On
RewriteBase /my_project_name/
# Do not enable rewriting for files or directories that exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [PT,L]
Upvotes: 2