如何从 url 中删除控制器名称使其在 codeigniter 中干净 [英] How to remove controller name from url making it clean in codeigniter

查看:23
本文介绍了如何从 url 中删除控制器名称使其在 codeigniter 中干净的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下网址..

http://localhost/ci/site_controller/home

我想从 url 中删除 site_controller controller 导致..

I want to remove site_controller controller from url resulting in..

 http://localhost/ci/home

如何在 CodeIgniter 中执行此操作?

How can I do this in CodeIgniter ?

注意:如果你问我尝试了什么,而不是我刚刚在谷歌上搜索过,因为我不知道如何使用 mod_rewrite.

Note: If you'll ask what I've tried than I've just done searching over Google as I don't know how to use mod_rewrite.

编辑

我的routes.php中有这个

I have this in my routes.php

$route['default_controller'] = "site_controller/home";
$route['ci/home'] = 'ci/site_controller/home';
$route['404_override'] = '';

但还是不行!

.htaccess

RewriteEngine On
RewriteBase /ci/
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

ErrorDocument 404 /index.php

推荐答案

您可以为每个 url 设置路由:

You can set your a route for each url:

在你的 config/routes.php 文件中,像这样设置每个页面:

In your config/routes.php file, just set each page like this:

$route['ci/home'] = "ci/site_controller/home";

这篇关于如何从 url 中删除控制器名称使其在 codeigniter 中干净的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆