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

2021-12-21 00:00:00 php codeigniter clean-urls mod-rewrite

我有以下网址..

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";

相关文章