【发布时间】:2011-10-08 22:55:10
【问题描述】:
我无法将可变 URL 段重新路由到我设置的测试控制器。我希望案例 4 重定向到我的测试控制器。
案例 1(有效) 转到 URL http://localhost/2fb/index.php/redirect/test
//输出“测试”
Case2(不起作用)转到 URL http://localhost/2fb/redirect/test
//output "在此找不到请求的 URL /2fb/redirect/test 服务器。”
案例 3(有效) 转到 URL http://localhost/2fb/
//输出 -> 加载我的欢迎控制器。
Case4(不起作用)转到 URL http://localhost/2fb/abc
//output "在此找不到请求的 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 文件的存在。
【问题讨论】:
-
我修好了。两件事,我在 2fb 的根目录而不是在应用程序文件夹中编写和修改了 .htaccess 文件。我还在应用程序文件夹中有另一个 .htaccess 文件,其中写入了
deny from all。在下面答案中的指令的帮助下,我删除了这个文件并用自定义文件替换了它。
标签: php apache .htaccess codeigniter routing