本文介紹了如何從 url 中刪除控制器名稱使其在 codeigniter 中干凈的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我有以下網(wǎng)址..
http://localhost/ci/site_controller/home
我想從 url 中刪除 site_controller
controller 導(dǎo)致..
I want to remove site_controller
controller from url resulting in..
http://localhost/ci/home
如何在 CodeIgniter 中執(zhí)行此操作?
How can I do this in CodeIgniter ?
注意:如果你問我嘗試了什么,而不是我剛剛在谷歌上搜索過,因?yàn)槲也恢廊绾问褂?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中有這個(gè)
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
推薦答案
您可以為每個(gè) url 設(shè)置路由:
You can set your a route for each url:
在你的 config/routes.php 文件中,像這樣設(shè)置每個(gè)頁面:
In your config/routes.php file, just set each page like this:
$route['ci/home'] = "ci/site_controller/home";
這篇關(guān)于如何從 url 中刪除控制器名稱使其在 codeigniter 中干凈的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!