Codeigniter删除.php并路由到index.php

时间:2013-04-19 15:45:19

标签: php .htaccess codeigniter

如果用户关注此网址:

http://localhost/events/info.php

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

http://localhost/events/info

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

3 个答案:

答案 0 :(得分:1)

使用

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

答案 1 :(得分:0)

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

通常我们已经没有了.php

http://localhost/events/info

要路由到index.php(在视图文件夹中):您只需在控制器文件中执行此操作。

<强>控制器/ events.php

function info(){
 redirect('events/index');
}

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

答案 2 :(得分:0)

使用.htaccess

可以实现301重定向
Redirect 301 events/info.php http://localhost/events/info

您可能会发现this tool对于生成重定向非常有用。


如果您只想将网址:http://localhost/events/info.php发送到info控制器中的events功能,那么您 不能移除{来自网址的{1}},您可以在.php中添加route

application/config/routes.php

如果您还没有,那么您还必须删除$route['events/info.php'] = 'events/info'; CodeIgniter's user guide explains how to do this.

如果您想从所有网址中删除index.php以使其看起来更干净,那么可以使用大量资源,包括other answers on SO