3

我正在使用 PHP codeigniter 和 chriskacerguis/codeigniter-restserver。

在日志文件中,我看到 404。因为/index是如何在末尾追加的。正确的 url 是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

任何人都可以告诉我为什么 /index 会在末尾追加或任何解决方案。

我的 .htaccess 看起来像这样。

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

3 回答 3

2

如果您想index.php从 URL 中删除,那么遵循代码肯定会为您工作。

<IfModule mod_rewrite.c>
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
<IfModule mod_rewrite.c>
于 2016-02-02T07:24:50.197 回答
0

这段代码对我有用

    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]
于 2016-02-02T07:32:56.260 回答
0

请删除 codeIgniter Framework 配置文件中的 index.php

$config['index_page'] = '';

并应用以下htaccess编码

RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|css|images|robots\.txt)
RewriteRule .* index.php/$0 [PT,L]
于 2016-02-02T07:28:44.480 回答