我有以下网址..
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 中干净的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!