yii url隐藏index.php
yii url隱藏index.php的方法:首先在web根目錄下增加“.htaccess”文件;然后修改配置“config/web.php”;最后將“AllowOverride None”修改為“AllowOverride All;”即可。
推薦:《PHP視頻教程》《yii教程》
Yii 框架開啟 URL 美化,隱藏 index.php [ 2.0 版本 ]
url美化
目的:將 http://localtest/yii/web/index.php?r=hello/index
美化成:http://localtest/yii/web/hello/index
這里我是用的wampserver新建了一個localtest站點(詳情可點擊這里點擊這里),并將yii的basic文件夾重新命名為yii。
對比上面的兩個地址,其實就是把index.php?r=隱藏。
這里分兩步:
1、增加.htaccess文件
在web根目錄下增加.htaccess文件,內(nèi)容為:
RewriteEngine On
DirectoryIndex index.html index.php
# 如果是一個目錄或者文件,就訪問目錄或文件
RewriteCond %{REQUEST_FILENAME} !-d
#如果文件存在,就直接訪問文件,不進行下面的RewriteRule
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php
無法直接創(chuàng)建.htaccess,可以先創(chuàng)建一個txt文件,然后另存為…,保存為文件名為.htaccess,保存類型選擇所有文件即可。
2、配置config/web.php 在config/web.php中的components數(shù)組中增加這一項:
'urlManager' => [
// //開啟url美化
'enablePrettyUrl' => true,
// //隱藏index.php
'showScriptName' => false,
// //禁用嚴(yán)格匹配模式
'enableStrictParsing' => false,
// //url后綴名稱
// 'suffix'=>'.html',
'rules' => [
],
],
這時,可以將URL中的index.php?r=刪除,如果出現(xiàn)404報錯,可以查看服務(wù)器的配置,我用的是phpstudy中集成的apache 需要檢查一下配置
conf\\httpd.conf中,開啟 apache 的 mod_rewrite 模塊
去掉 LoadModule rewrite_module modules/mod_rewrite.so 前的“#”符號;
然后修改 apache 的 AllowOverride
將 AllowOverride None 修改為 AllowOverride All;
由于我是在conf\\extra\\httpd-vhosts.conf中配置了站點,所以需要同步去httpd-vhosts.conf中將對應(yīng)站的 AllowOverride None 修改為 AllowOverride All;
至此,我就可以用 http://localtest/yii/web/hello/index
來訪問 http://localtest/yii/web/index.php?r=hello/index
總結(jié)
以上是生活随笔為你收集整理的yii url隐藏index.php的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php的sort函数用法
- 下一篇: linux下如何开启PHP报错