在使用路由设置从URL中删除控制器名称后,为什么它会将我重定向到带有控制器名称的URL


After removing controller name from the URL using route setting why it redirect me to URL with controller name

使用路由设置从URL中删除控制器名称后,为什么它会将我重定向到带有控制器名称的URL

    <form method="POST" action="<?php echo site_url('user/dashboard');?>">
            <table border="0" cellpadding="0" cellspacing="0">
            <tr>
                <th>Username</th>
                <td><input type="text"  class="login-inp" /></td>
            </tr>
            <tr>
                <th>Password</th>
                <td><input type="password" value="************"  onfocus="this.value=''" class="login-inp" /></td>
            </tr>
            <tr>
                <th></th>
                <td valign="top"><input type="checkbox" class="checkbox-size" id="login-check" /><label for="login-check">Remember me</label></td>
            </tr>
            <tr>
                <th></th>
                <td><input type="submit" class="submit-login"  /></td>
            </tr>
            </table>
    </form>

这是我的路由设置

$route['default_controller'] = 'user';
$route['(:any)'] = "user/$1";
$route['(:any)/(:any)'] = "user/$1/$1";
$route['(:any)/(:any)/(:any)'] = "user/$1/$1/$1";

当我点击提交按钮时它会将我重定向到这个URL

我不希望控制器名是URL

http://localhost/grant/user/dashboard

我想要这样

http://localhost/grant/dashboard

我认为路由设置是好的,.htaccess文件可能有问题,任何帮助将不胜感激。

问题出在你的route setting。您需要使用/edit .htaccess file.

改变

$route['(:any)'] = "user/$1";
action="<?php echo site_url('user/dashboard');?>

$route['dashboard'] = "user/$1";
action="<?php echo site_url('dashboard');?>

注意

在尝试上面的代码之前,注释/禁用下面的代码。

$route['(:any)/(:any)'] = "user/$1/$1";
$route['(:any)/(:any)/(:any)'] = "user/$1/$1/$1";