用户
 找回密码
 入住 CI 中国社区
搜索
查看: 1727|回复: 2
收起左侧

[URL] 自定义路由在服务器上报404

[复制链接]
发表于 2018-7-6 16:25:03 | 显示全部楼层 |阅读模式
【求助】自定义路由在本地是可以访问的,上传服务器,welcome控制器的index方法是可以直接访问的,但是自定义的路由就出现了问题,报404.
$route['default_controller'] = 'api_controller';
$route['_API/(:any)'] = 'api_controller/$1';

服务器用的是Nginx
发表于 2018-7-6 19:46:30 | 显示全部楼层
nginx是否有隐藏index.php?
 楼主| 发表于 2018-7-9 09:55:34 | 显示全部楼层
warith 发表于 2018-7-6 19:46
nginx是否有隐藏index.php?

server {
        listen 8881;
        listen [::]:8881;
        server_name  localhost:8881;

        root   /srv/www/develop/ChineseFood;
        index index.php  index.html index.htm;

        location / {
                # 这里使用try_files进行url重写,不用rewrite了。
                try_files $uri $uri/ /index.php?$uri&$args;
                #root /srv/www/develop/ChineseFood;
                index  index.php;
                #if (!-e $request_filename) {
                #       rewrite ^/(.*)$ /index.php/$1 last;
                #       break;
                #}
        }

        location ~ \.php($|/) {
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index  /index.php;
            fastcgi_split_path_info  ^(.+\.php)(/.+)$;
            fastcgi_param   PATH_INFO        $fastcgi_path_info;
            fastcgi_param   PATH_TRANSLATED  $document_root$fastcgi_path_info;
            fastcgi_param   SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include         fastcgi_params;
        }

        if (!-e $request_filename) {
            rewrite ^/(.*)$ /index.php/$1 last;
            break;
        }
}
这是服务器Nginx的配置,我根据网上,换了好几个版本,结果都是同样的结果

本版积分规则