如何从 url 中删除控制器名称使其在 codeigniter 中干净

How to remove controller name from url making it clean in codeigniter(如何从 url 中删除控制器名称使其在 codeigniter 中干净)
本文介绍了如何从 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 中干净的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Codeigniter htaccess to remove index.php and www(Codeigniter htaccess 删除 index.php 和 www)
htaccess mod_rewrite part of url to GET variable(htaccess mod_rewrite url 的一部分到 GET 变量)
Replacing a querystring parameter value using mod_rewrite(使用 mod_rewrite 替换查询字符串参数值)
.htaccess in subdirectory #39;overriding#39; parent htaccess(子目录“覆盖父 htaccess 中的 .htaccess)
How to rewrite SEO friendly url#39;s like stackoverflow(如何像stackoverflow一样重写SEO友好的url)
Is it okay to have a very long .htaccess file?(有一个很长的 .htaccess 文件可以吗?)