Php 如何在末尾删除/索引
我正在使用PHP codeigniter和chriskacerguis/codeigniter restserver 在日志文件中,我看到404。因为一些/index是如何在末尾追加的。 正确的url是api/CurrentYearPhp 如何在末尾删除/索引,php,codeigniter,codeigniter-restserver,Php,Codeigniter,Codeigniter Restserver,我正在使用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 sanitize
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>
重新启动发动机
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_URI}^/(favicon\.ico | apple touch图标。*\.png)$[NC]
重写规则(+)index.php?p=$1[QSA,L]
如果您想从URL中删除index.php
,那么下面的代码肯定适合您
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
<IfModule mod_rewrite.c>
重新启动发动机
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$index.php/$1[L]
请删除codeIgniter框架配置文件中的index.php
$config['index_page'] = '';
并应用下面的访问编码
RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|css|images|robots\.txt)
RewriteRule .* index.php/$0 [PT,L]
这个代码对我有用
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]
是否删除配置文件中的index.php?是的,它类似于$config['index_page']='';共享您的主机url?就像在控制器后省略函数名一样,CodeIgniter将使用默认的函数名,即
索引
函数。这就是为什么它被添加到您的url。因此,在不指定函数的情况下访问控制器CurrentYear
,将使CodeIgniter查找其索引
函数。在这种情况下,在扩展REST\u控制器时,必须调用函数index\u()
。如果您没有该功能,将返回404错误。(假设api
是一个文件夹,CurrentYear
是一个控制器)。我们可以从末尾删除“index”吗?