溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

php ci這樣去掉index.php

發(fā)布時(shí)間:2020-11-11 09:52:47 來(lái)源:億速云 閱讀:97 作者:小新 欄目:編程語(yǔ)言

這篇文章給大家分享的是有關(guān)php ci這樣去掉index.php的內(nèi)容。小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧。

php ci去掉index.php的方法:首先打開apache的配置文件;然后在ci的根目錄下建立“.htaccess”;最后添加內(nèi)容“RewriteEngine on RewriteCond $1 !^(index.php)”并保存即可。

CodeIgniter去掉url中的index.php

RewriteEngine命令需要rewrite mod的支持

$>cd /etc/apache2/mods-enabled 切換到apache下的mods-enabled目錄

$>sudo ln -s ../mods-available/rewrite.load rewrite.load 啟用rewrite mod

$>sudo /etc/init.d/apache2 restart 重啟apache服務(wù)器。 或者在apache的配置文件httpd.conf中將#LoadModule rewrite_module modules/mod_rewrite.so前的#去掉,再重啟服務(wù)器。

或者

sudo a2enmod rewrite

CodeIgniter去掉url中的index.php

CodeIgniter去掉url中的index.php CI默認(rèn)中url中帶index.php,比如 http://localhost/index.php/blog/comment/1.html 去掉這個(gè)index.php步驟:

1.打開apache的配置文件,conf/httpd.conf :

LoadModule rewrite_module modules/mod_rewrite.so,把該行前的#去掉。

搜索 AllowOverride None(配置文件中有多處),看注釋信息,將相關(guān).htaccess的該行信息改為AllowOverride All。

2.在CI的根目錄下

即在index.php,system的同級(jí)目錄下,建立.htaccess,直接建立該文件名的不會(huì)成功,可以先建立記事本文件,另存為該名的文件即可。內(nèi)容如下(CI手冊(cè)上也有介紹):

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

就可以去掉 index.php 了。

要注意 /index.php/$1 要根據(jù)你目錄(Web 目錄,比如 http://www.domain.com/index.php)的實(shí)際情況來(lái)定,比如網(wǎng)站根目錄是 /ci/index.php 則要寫成 /ci/index.php/$1

RewriteCond $1 !^(index.php|images|robots.txt) 上面的代碼意思是排除某些目錄或文件,使得這些目錄不會(huì) rewrite 到 index.php 上,這一般用在圖片、js、css 等外部資源上。也就是說(shuō)非 PHP 代碼都要排除出去。(這里我排除了 images 目錄和 robots.txt 文件,當(dāng)然 index.php 也應(yīng)該被排除)

3.

將CI中配置文件(system/application/config/config.php)中$config[‘index_page’] = &index.php&;將$config[‘index_page’] = &&; 。

ok,完成。還要記得重啟apache。

感謝各位的閱讀!關(guān)于php ci這樣去掉index.php就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI