CodeIgniter
Allen 2021-08-07 11:04:34 3082 0 0 0 0

首先,你要清楚自己的 Web 服务器是 Apache,支持 mod_rewrite,并且已经配置好 rewrite 相关的参数。

什么是 rewrtie 可以 Google 一下。

然后,在 CI 根目录下新建立一个配置文件,命名为: .htaccess

在里面这样写:

RewriteEngine on   
RewriteCond $1 !^(index.php|images|robots.txt)   
RewriteRule ^(.*)$ /index.php/$1 [L]

就可以去掉 index.php 了。要注意 /index.php/$1 要根据你目录(Web 目录,比如 http://www.domain.com/index.php)的实际情况来定,比如网站根目录是 /ci/index.php 则要写成 /ci/index.php/$1

RewriteCond $1 !^(index.php|images|robots.txt)

上面的代码意思是排除某些目录或文件,使得这些目录不会 rewrite 到 index.php 上,这一般用在图片、js、css 等外部资源上。也就是说非 PHP 代码都要排除出去。(这里我排除了 images 目录和 robots.txt 文件,当然 index.php 也应该被排除)

哦,对了,还要修改 config.php 这个文件中的下列内容:

/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = "index.php";

把其中的 "index.php" 改成 "" 就可以了。(好像这个改成空也可以)


【版權聲明】
本文爲轉帖,原文鏈接如下,如有侵權,請聯繫我們,我們會及時刪除
原文鏈接:https://codeigniter.org.cn/forums/forum.php?mod=viewthread&tid=4&extra=page%3D1
Tag: PHP CodeIgniter
歡迎評論
未登錄,
請先 [ 註冊 ] or [ 登錄 ]
(一分鍾即可完成註冊!)
返回首頁     ·   返回[CodeIgniter]   ·   返回頂部