0

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 !

1
  • We would need to see that you have attempted a solution first. Can you show us some example code first? Commented Mar 1, 2014 at 13:59

5 Answers 5

2

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]
Sign up to request clarification or add additional context in comments.

Comments

1

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...

Comments

0

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]

Comments

0
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 ...

Comments

0

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]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.