在CI中重新路由URL's出现问题


Trouble re-routing URL's in CI

我在将变量URL段重新路由到我设置的测试控制器时遇到了麻烦。我想让case 4重定向到我的测试控制器。

Case1 (works) go to URLhttp://localhost/2fb/index.php/redirect/test

//输出"测试"

Case2(不工作)去URL http://localhost/2fb/redirect/test

//输出"请求的URL/2fb/redirect/test没有找到服务器。"

Case3 (works)去URL http://localhost/2fb/

//output ->加载Welcome Controller.

Case4(不工作)去URL http://localhost/2fb/abc

//输出"请求的URL/2fb/redirect/test/abc没有找到服务器。"

我的routes.php文件是这样的:

$route['default_controller'] = "welcome";
$route['404_override'] = '';
$route["2fb/(:any)"] = "redirect/test";

redirect.php控制器

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Redirect extends CI_Controller {
    public function index()
    {    
    } 
    public function test()
    {
        echo "testing";                       
    } 
}

config . php:

$config['index_page'] = '';

。htaccess:

# Code Igniter Htaccess Rules
<IfModule mod_rewrite.c>
  RewriteEngine on
   # Rewrite URLs of the form 'x' to the form 'index.php/x'.
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>

我相信我的Apache配置是正确的,因为它考虑到。htaccess文件的存在

也许可以尝试另一个htaccess:

RewriteRule ^$ /index.php [L]
RewriteCond $1 !^(index'.php|css|img|images|js|scripts|system|uploads|robots'.txt|favicon'.ico|favicon'.png)
RewriteRule ^(.*)$ /index.php/$1 [L]

你还需要:

$route["2fb/(:any)"] = "redirect/test";

你能不能:

$route["2fb/(:any)"] = "redirect";

$route["2fb/(:any)"] = "redirect/$1";

fixed.

  • 。htaccess文件中有deny from all