標籤:yii .htaccess url apache it
今天學習那個yii的時候,覺得URL太麻煩,想自己配置一下,於是就百度了一下,然後自己總結下,留著後面配置的時候看看。
yii架構中有個很重要的組件:URL Management(網址管理)
進行yii偽靜態就是只需要配置這個就可以了。
沒有配置之前是這個樣子的:
配置成功後的URL就是這樣的:
第一步:配置URL Management(網址管理)
只需要在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>
第二步:進行apache配置
yii中有個檔案:.htaccess 用來專門配置apache伺服器的,這個檔案下面配置輸入下面的代碼
<IfModule mod_rewrite.c>Options +FollowSymLinksIndexIgnore */*RewriteEngine on# if a directory or a file exists, use it directlyRewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-d# otherwise forward it to index.phpRewriteRule . index.php</IfModule>
這個檔案配置好了之後,一定要把apache中的rewrite模組開啟:
然後就OK了。
整個URL的配置就已經完成了。
Yii 1.0 偽靜態即Yii配置Url重寫