Search code examples
php.htaccesscodeigniter

Remove the index.php in routing in Codeigniter


I put my folder as public_html/vote

And this is the default behavior of the server

http://mydomain.com/~voteimbo/  <===the public_html folder
http://mydomain.com/~voteimbo/vote/ <==== the vote folder in public_html

The problem is , if I try routing in route.php, unless I add the index.php in my url otherwise it show 404 (The server 404, not codeigniter)

 e.g. $route["test"] = front_end/index

 http://mydomain.com/~voteimbo/vote/index.php/test <==== work
 http://mydomain.com/~voteimbo/vote/test <==== 404

Here is my setting

config.php

$config['base_url'] = 'http://mydomain.com/~voteimbo/vote/';
$config['index_page'] = '';

route.php

$route['default_controller'] = "front_end/check_date";
$route['404_override'] = '';
$route['test'] = "front_end/index"; 

htaccess

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php?/$0 [PT,L] 

Thanks for helping

Update :

Attempted the approach here:

CodeIgniter removing index.php not working

but the output is

Array
(
)

so I wonder what is the problem? thanks


Solution

  • Okay, assuming (as you stated) that your codeigniter setup is stored in the directory /vote/.

    You should be able to do something like this in the htaccess file to be able to access it without the index.php

    RewriteEngine on
    RewriteBase /vote/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond $1 !^(index\.php|images|robots\.txt)
    RewriteRule ^(.*)$ /index.php/$1 [L]
    

    Here is some more reading related to Codeigniter URL's