[置頂] Yii 1.0 偽靜態(tài)即Yii配置Url重寫
來源:程序員人生 發(fā)布時間:2014-11-05 08:14:37 閱讀次數(shù):3054次
今天學習那個yii的時候,覺得URL太麻煩,想自己配置1下,因而就百度了1下,然后自己總結(jié)下,留著后面配置的時候看看。
yii框架中有個很重要的組件:URL Management(網(wǎng)址管理)
進行yii偽靜態(tài)就是只需要配置這個就能夠了。
沒有配置之前是這個模樣的:

配置成功后的URL就是這樣的:

第1步:配置URL Management(網(wǎng)址管理)
只需要在config文件夾下面的main.php文件中進行配置就行了
'components' => array(
'urlManager' => [
'showScriptName' => false,//這里是隱藏index.php那個路徑的
'urlFormat' => 'path',
'rules' => [
'<controller:w+>/<id:d+>' => '<controller>/view',
'<controller:w+>/<action:w+>/<id:d+>' => '<controller>/<action>',
'<controller:w+>/<action:w+>' => '<controller>/<action>'
]
],
'user' => array(
// enable cookie-based authentication
'allowAutoLogin' => true
),<span style="font-family: Arial, Helvetica, sans-serif;">)</span>
第2步:進行apache配置
yii中有個文件:.hthttp://www.vxbq.cn/access/ 用來專門配置apachehttp://www.vxbq.cn/server/的,這個文件下面配置輸入下面的代碼
<IfModule mod_rewrite.c>
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
</IfModule>
這個文件配置好了以后,1定要把apache中的rewrite模塊開啟:

然后就OK了。
全部URL的配置就已完成了。
生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對您的學習有所幫助,可以手機掃描二維碼進行捐贈