删除.php并路由到index.php


Codeigniter Remove .php and route to index.php

如果用户遵循此url:

http://localhost/events/info.php

我如何通过htaccess删除。php扩展名,以便用户路由到index.php和我的事件控制器到信息函数?我想创建301重定向。

http://localhost/events/info

我有旧的索引链接,我需要重定向到我的控制器函数,所以我没有得到404。

use

RewriteEngine On
RewriteRule ^events/info/$ index.php [L,QSA]

您使用的是哪个版本的CI ?

通常没有。php

我们已经得到了这样的结果
http://localhost/events/info

要路由到index.php(在视图文件夹):你只需要在你的控制器文件中这样做。

控制器/events.php

function info(){
 redirect('events/index');
}
function index()
{
 $this->load->view('index.php');
}

可以使用.htaccess实现301重定向

Redirect 301 events/info.php http://localhost/events/info

您可能会发现这个工具对于生成重定向很有用。


如果您只想将URL: http://localhost/events/info.php路由到events控制器中的info功能,那么您没有从URL中删除.php,您可以在application/config/routes.php中添加路由。

$route['events/info.php'] = 'events/info';

如果你还没有,那么你还必须删除index.php, CodeIgniter的用户指南解释了如何做到这一点。

如果您想从所有url中删除.php以使它们看起来更干净,那么有很多可用的资源,包括SO上的其他答案。