Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法在url中显示没有index.php的视图,Codeigniter中的默认控制器除外_Php_Codeigniter_Codeigniter 2 - Fatal编程技术网

无法在url中显示没有index.php的视图,Codeigniter中的默认控制器除外

无法在url中显示没有index.php的视图,Codeigniter中的默认控制器除外,php,codeigniter,codeigniter-2,Php,Codeigniter,Codeigniter 2,我在CodeIgniter中有一个路由问题,我搜索并尝试了stackoverflow上的其他链接,包括,但我的问题没有解决。当我从这个url运行时,它成功地为输出提供了test.php页面的视图页面,但问题是假设也有test2视图和控制器,所以我不能通过这个url直接加载它,但我可以加载它。我希望我可以在url之间不使用index.php运行我的代码 test.php .htaccess 重新启动发动机 #使用应用程序目录重命名“MyProject/” #例如,将整个CodeIgniter应用

我在CodeIgniter中有一个路由问题,我搜索并尝试了stackoverflow上的其他链接,包括,但我的问题没有解决。当我从这个url运行时,它成功地为输出提供了test.php页面的视图页面,但问题是假设也有test2视图和控制器,所以我不能通过这个url直接加载它,但我可以加载它。我希望我可以在url之间不使用index.php运行我的代码

test.php

.htaccess


重新启动发动机
#使用应用程序目录重命名“MyProject/”
#例如,将整个CodeIgniter应用程序重命名为“mysite”
#然后,“RewriteBase/”将类似于“RewriteBase/mysite”
#与第10行相同,“RewriteRule^(.*)$/MyProject//index.php#/$1[L]”类似于“RewriteRule^(.*)$/mysite/index.php/$1[L]”
重写数据库/我的项目/
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$/MyProject/index.php/$1[L]

您需要从url中删除index.php。创建.htacces文件并放入根目录。复制此代码并运行

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
有关如何删除index.php表单url的更多信息,请尝试以下内容

推荐
.htaccess

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

我尝试了您的代码并键入了以下url,它给出了错误404未找到页面。但通过它,我不希望index.php出现在两者之间。请在config文件夹中打开config.php文件,并将$config['index\u page']=“index.php”替换为$config['index\u page']=“尝试回复$config['uri协议']=“AUTO”//替换为下面的代码$config['uri\u protocol']=“REQUEST\u uri”问题是相同的,.haccess文件是否有任何问题:RewriteCond%{REQUEST\u FILENAME}上的RewriteEngine-f RewriteCond%{REQUEST_FILENAME}-重写规则^(.*)$index.php/$1[L]
<?php
class test extends CI_Controller{

    function __construct(){
        parent::__construct();
    }

    public function index(){
        $this->load->view('test');
    }
}
?>
routes.php
$route['default_controller'] = "test";
<IfModule mod_rewrite.c> 
 RewriteEngine On
 #rename "MyProject/" with your application directory 
 #For example you rename the entire CodeIgniter application as "mysite" 
 #then, the "RewriteBase /" will be like this "RewriteBase /mysite" 
 #same as at line number 10, "RewriteRule ^(.*)$ /MyProject//index.php #/$1 [L]" will be like this "RewriteRule ^(.*)$ /mysite/index.php/$1 [L]"
 RewriteBase /MyProject/
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.*)$ /MyProject/index.php/$1 [L]
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]