重命名了代码点火器控制器中的方法.如何使用 .htaccess 重定向


Renamed a method in codeigniter's controller. How do I redirect using .htaccess?

在看了很多地方之后,终于把它贴在这里。

我已经将代码点火器控制器中的一种方法从类详细信息重命名为类详细信息。

我在.htaccess中使用以下代码,但它不起作用

RewriteRule ^classDetails/(.*)$ class-details/$1 [R=301,L]

我也在/application/config/routes 中尝试过这段代码.php

$route['classDetails'] = 'class-details';

我也试过

$routes['classDetails'] = 'class-details';

我什至尝试在代码点火器中使用_remap(),如下所示

public function _remap($method, $params = array()){
switch ($method){
    case 'classDetails':$method='class_details'; break;
};
if (method_exists($this, $method))
{
    return call_user_func_array(array($this, $method), $params);
}
show_404();
}

无论我做什么,它都会转到 404 页

我哪里做错了?

[编辑]

我的方法名称是 class_details 我正在使用名为 MY_Router.php 的自定义核心类在 url 中覆盖它

首先,您没有对方法名称使用正确的约定,您可以使用类详细信息作为方法名称,您只能使用所有小写或驼峰大小写作为方法名称,否则它将永远无法正常工作。 您可以将方法名称指定为 classDetails,在路由中您必须编写类似这样的东西

 $routes['class-details'] = '<controllerName>/classDetails';