-1

I am trying to remove the index.php segment from my project, but I can't. I tested several articles quoted here in StackOverflow, but still unable to.

This is my project structure:

(In /var/www/project directory)
project
--assets
--system
--.htaccess
--index.php
--info.php
--quickmenu.php

PHP version: 5.3.10
SO: Ubuntu 12.04
Apache version: 2.2.22
CodeIgniter: 2.1.3

My config.php file:

$config['base_url'] = "HTTP://".$_SERVER['HTTP_HOST']."/project/";

$config['index_page'] = "";

$config['uri_protocol'] = "REQUEST_URI";


$config['url_suffix'] = "";


$config['language'] = "portugues";

$config['charset'] = "iso-8859-1";


$config['enable_hooks'] = FALSE;


$config['subclass_prefix'] = 'MY_';



$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';


$config['enable_query_strings'] = FALSE;
$config['directory_trigger'] = 'd';  // experimental not currently in use
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';

$config['log_threshold'] = '1';


$config['log_path'] = '';

$config['log_date_format'] = 'Y-m-d H:i:s';


$config['cache_path'] = '/var/ci/cache/';


$config['encryption_key'] = "q7uP3mprMYuFFvbNcXyC6uPXs2ZUezxh";


$config['sess_cookie_name']     = 'ci_session';
$config['sess_expiration']      = 7200;
$config['sess_encrypt_cookie']          = FALSE;
$config['sess_use_database']            = TRUE;
$config['sess_table_name']      = 'ci_sessions';
$config['sess_match_ip']        = FALSE;
$config['sess_match_useragent']         = TRUE;
$config['sess_time_to_update']      = 300;
$config['sess_storage']                 = 'database';

$config['sess_database']                = 'default';
$config['sess_timeout']                 = 7200;
$config['sess_destroy_on_timeout']      = FALSE;
$config['sess_update_interval']         = 180;
$config['sess_gc_probability']          = 10;
$config['sess_http_only']               = FALSE;
$config['sess_secure']                  = FALSE;
$config['sess_forwarded_ip']            = FALSE;


$config['cookie_prefix']    = "";
$config['cookie_domain']    = "";
$config['cookie_path']      = "/";

$config['global_xss_filtering'] = FALSE;

$config['compress_output'] = FALSE;


$config['time_reference'] = 'local';


$config['rewrite_short_tags'] = FALSE;

/* End of file config.php */
/* Location: ./system/application/config/config.php */

My .htaccess file:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /project/

    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]


    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule> 

Complement:

With the url doesn't work:

http://localhost/project/#../directory/controller/method

With these urls works:

http://localhost/project/#index.php/directory/controller/method
http://localhost/project/index.php/#directory/controller/method
mayconfsbrito
  • 1,455
  • 3
  • 20
  • 37
  • Hope this helps : http://stackoverflow.com/questions/13714057/codeigniter-remove-index-php-with-htaccess – rajmathan Jan 20 '14 at 12:16

5 Answers5

3

Try with changing uri_protocol from AUTO to REQUEST_URI

$config['uri_protocol'] = "REQUEST_URI";

You can refer this link : http://taggedzi.com/articles/display/codeigniter-2-htaccess-and-friendly-urls

Balaji Kandasamy
  • 4,115
  • 10
  • 36
  • 58
1

If you are uploading on the server, then Remove RewriteBase /project/

and write RewriteBase /

I was doing the same mistake. I just tested and it worked.

Chopra
  • 551
  • 3
  • 8
  • 21
1

Change your config.php as:

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

$config['uri_protocol'] = "ORIG_PATH_INFO";

Then place this rule in your /project/.htaccess:

RewriteEngine On

RewriteBase /project/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php/$1 [L]

Also make sure there is no .htaccess present in /project/directory/.

anubhava
  • 664,788
  • 59
  • 469
  • 547
0

I solved this problem.

Was missing install the mod_rewrite package on my PHP. So after this just config the config/config.php and .htaccess files.

Below the article who I used for install mod_rewrite module for PHP in my UBUNT:

How to enable mod_rewrite for Apache 2.2

Thanks everyone for advice, if not for them I would not have tried this workaround.

Community
  • 1
  • 1
mayconfsbrito
  • 1,455
  • 3
  • 20
  • 37
0

I found the exact solution for mine.You can try it. I assume that the most important is RewriteBase / and ./CI/ will be your application contained folder name. Example: CI/application So be careful.

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

But if you are svn server then use: RewriteRule ^(.*)$ ./index.php/$1 [L]

These will work if you are putting with/without index.php here`ex: http://kabircse.tk/CI/ or http://kabircse.tk/CI/index.php

Both will find out your route controller. If your route controller is mc then it will find it as http://kabircse.tk/CI/mc