Codeigniter 3路由错误
Codeigniter 3 routing error
我在 codeigniter 3 上遇到路由错误。
未找到
在此服务器上找不到请求的 URL /index.php。 Apache/2.4.7 (Ubuntu) 服务器
我做了什么。
我的.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/ [L]
</IfModule>
同时设置AllowOverride ALL
我的控制器Test.php
class Test extends CI_Controller {
public function index(){
print_r('test');
die();
}
}
我的路线:$route['test/(:any)'] = 'test/';
并尝试通过 url 到达此页面:
http://localhost/codeigniter/test/index.php
http://localhost/codeigniter/test/
试试这个.htaccess
RewriteEngine on
RewriteCond !^(index\.php|assets|image|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/ [L,QSA]
如果您正在访问控制器,只需键入(假定 codeigniter
作为您的项目文件夹名称)
http://localhost/codeigniter/test/
这是什么原因$route['test/(:any)'] = 'test/';
?
这指定将有参数传递给它。它可以是数字或字母。例如 http://localhost/codeigniter/test/aaa
或 http://localhost/codeigniter/test/25
您的问题是您传递的 uri(2),当您尝试使用此路由时,uri(2) 用于控制器的方法 codeigniter/test/1
您应该首先指定您的方法,这样就可以了$route['test/(any)'] = 'test/index/$i';
顺便说一句 codeigniter
被认为是你的 uri(0)。
我在 codeigniter 3 上遇到路由错误。
未找到 在此服务器上找不到请求的 URL /index.php。 Apache/2.4.7 (Ubuntu) 服务器
我做了什么。 我的.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/ [L]
</IfModule>
同时设置AllowOverride ALL
我的控制器Test.php
class Test extends CI_Controller {
public function index(){
print_r('test');
die();
}
}
我的路线:$route['test/(:any)'] = 'test/';
并尝试通过 url 到达此页面:
http://localhost/codeigniter/test/index.php
http://localhost/codeigniter/test/
试试这个.htaccess
RewriteEngine on
RewriteCond !^(index\.php|assets|image|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/ [L,QSA]
如果您正在访问控制器,只需键入(假定 codeigniter
作为您的项目文件夹名称)
http://localhost/codeigniter/test/
这是什么原因$route['test/(:any)'] = 'test/';
?
这指定将有参数传递给它。它可以是数字或字母。例如 http://localhost/codeigniter/test/aaa
或 http://localhost/codeigniter/test/25
您的问题是您传递的 uri(2),当您尝试使用此路由时,uri(2) 用于控制器的方法 codeigniter/test/1
您应该首先指定您的方法,这样就可以了$route['test/(any)'] = 'test/index/$i';
顺便说一句 codeigniter
被认为是你的 uri(0)。