apache服務(wù)器的配置
修改httpd.conf配置文件
1、將LoadModule rewrite_module modules/mod_rewrite.so前面的注釋#號去掉。
2、添加如下內(nèi)容:
<directory> ????#?use?mod_rewrite?for?pretty?URL?support ????RewriteEngine?on ????#?If?a?directory?or?a?file?exists,?use?the?request?directly ????RewriteCond?%{REQUEST_FILENAME}?!-f ????RewriteCond?%{REQUEST_FILENAME}?!-d ????#?Otherwise?forward?the?request?to?index.php ????RewriteRule?.?index.php ????#?...other?settings... </directory>
注意其中的path/to/basic/web修改成你的根目錄,最后不要忘記重啟apache服務(wù)器。
(推薦教程:yii框架)
nginx服務(wù)器的配置
修改nginx.conf配置文件,在域名對應(yīng)的server{}內(nèi)添加如下內(nèi)容:
location?/?{ ????#?Redirect?everything?that?isn't?a?real?file?to?index.php ????try_files?$uri?$uri/?/index.php$is_args$args; }
最后不要忘記重載配置文件。
YII2代碼的配置
修改config/web.php,在components數(shù)組中添加如下內(nèi)容(去掉前后的注釋)
'components'?=>?[ ????... ????'urlManager'?=>?[ ????????'enablePrettyUrl'?=>?true, ????????'showScriptName'?=>?false, ????????'rules'?=>?[ ????????], ????], ????... ],
這時(shí)再刷新網(wǎng)頁,就能看到連接的形式發(fā)生了改變。此時(shí)默認(rèn)會將/index.php?r=controller/action這樣的形式修改為/controller/action(如果含有參數(shù),則將/index.php?r=controller/action&…改為/controller/action?…)。
更多編程相關(guān)內(nèi)容,請?jiān)L問php中文網(wǎng)yii框架欄目!
? 版權(quán)聲明
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載。
THE END