Yii 1.0 偽靜態即Yii配置Url重寫

來源:互聯網
上載者:User

標籤: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重寫

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.