3

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>
fresher
  • 399
  • 4
  • 23
  • are you remove index.php in config file ? – msvairam Feb 02 '16 at 07:22
  • yes it like $config['index_page'] = ''; – fresher Feb 02 '16 at 07:27
  • share you host url ? – msvairam Feb 02 '16 at 07:29
  • its like http://example.com/api/currentYear – fresher Feb 02 '16 at 07:32
  • When one omits the function name after the controller, Codeiginiter goes for the default one, which is the `index` function. That is why it is added to you url. Thus accessing the controller `CurrentYear` without specifying a function will make CodeIgniter look for its `index` function. In this case, as you extended REST_Controller, the function must be called `index_()`. If you do not have the function, 404 error will be returned. (Assuming that `api` is a folder and `CurrentYear` is a controller). – Hicaro Dec 25 '16 at 21:30

3 Answers3

2

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>
Muhammad Hassaan
  • 7,296
  • 6
  • 30
  • 50
0

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]
msvairam
  • 862
  • 5
  • 12
0

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]
Nazmul Alam
  • 109
  • 7