yii框架怎么配置pathinfo的模式 ? ?
第一次部署好Yii框架搭建的應用后,框架默認使用的不是PathInfo形式的URL,而是類似http://yourdomain.com/index.php?r=account/login 這樣的形式,這種URL不僅不美觀,而且不利于SEO,所以下面介紹在Yii中如何使用PathInfo形式的URL(注:開發(fā)環(huán)境基于wampserver2.4)。
1)打開protected/config/main.php配置文件,將下面這段urlManager代碼的注釋去掉:
'urlManager' => array( 'urlFormat' => 'path', 'rules' => array( '<controller:\w+>/<id:\d+>'=>'<controller>/view', '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>', '<controller:\w+>/<action:\w+>'=>'<controller>/<action>', ), ),
2)去掉以后,我們就可以使用類似http://yourdomain.com/index.php/controller/action這種形式的URL去訪問應用,但是接下來我們還要隱藏掉中間的那個index.php;
相關文章教程推薦:yii教程
3)在應用的根目錄下添加一個名為.htaccess的文件,并寫入以下內(nèi)容:
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
4)開啟apache的rewrite模塊,在httpd.conf中找到#LoadModule rewrite_module modules/mod_rewrite.so,把前面的“#”去掉;
5)重啟apache;
6)繼續(xù)編輯main.php文件,在剛才那個urlManager的數(shù)組中添加一個元素:
'urlManager' => array( 'urlFormat' => 'path', 'showScriptName' => false, // 添加這一行 'rules' => array( '<controller:\w+>/<id:\d+>'=>'<controller>/view', '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>', '<controller:\w+>/<action:\w+>'=>'<controller>/<action>', ), ),
7)完成!
更多yii編程入門技術,請持續(xù)關注PHP中文網(wǎng)??!? ??
以上就是yii框架怎么配置pathinfo的模式的詳細內(nèi)容,更多請關注php中文網(wǎng)其它相關文章!
每個人都需要一臺速度更快、更穩(wěn)定的 PC。隨著時間的推移,垃圾文件、舊注冊表數(shù)據(jù)和不必要的后臺進程會占用資源并降低性能。幸運的是,許多工具可以讓 Windows 保持平穩(wěn)運行。
Copyright 2014-2025 http://www.miracleart.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號