how to get rid of /index at end

102 Views Asked by At

I am using PHP codeigniter and chriskacerguis/codeigniter-restserver.

In log file I am seeing 404. because some how /index is getting append at end. correct url is api/CurrentYear

DEBUG - 2016-02-02 02:14:48 --> UTF-8 Support Enabled
DEBUG - 2016-02-02 02:14:48 --> Global POST, GET and COOKIE data sanitized
ERROR - 2016-02-02 02:14:48 --> 404 Page Not Found: api/CurrentYear/index

Can anyone give me clue why /index is getting append at end or any solution.

my .htaccess look like this.

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
    RewriteRule (.+) index.php?p=$1 [QSA,L]
</IfModule>
3

There are 3 best solutions below

1
On

If you want to remove index.php from URL then follow code will surely works for you.

<IfModule mod_rewrite.c>
RewriteEngine on

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

Please remove the index.php in codeIgniter Framework config file

$config['index_page'] = '';

And apply below htaccess coding

RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|css|images|robots\.txt)
RewriteRule .* index.php/$0 [PT,L]
0
On

This code works for me

    Options +FollowSymLinks
    RewriteEngine on
    RewriteCond $1 !\.(gif|jpg|shtml|ico|swf|wav|mp3|less|cur)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule (.*) index.php?p=$1 [QSA]